@maci-protocol/coordinator 0.0.0-ci.4a1da43 → 0.0.0-ci.4bfa285
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/LICENSE +1 -2
- package/README.md +31 -6
- package/build/hardhat.config.cjs +9 -3
- package/build/hardhat.config.cjs.map +1 -1
- package/build/hardhat.config.d.cts +9 -4
- package/build/scripts/generateKeypair.js +2 -2
- package/build/scripts/generateKeypair.js.map +1 -1
- package/build/tests/constants.d.ts +3 -4
- package/build/tests/constants.d.ts.map +1 -1
- package/build/tests/constants.js +5 -4
- package/build/tests/constants.js.map +1 -1
- package/build/tests/e2e.deploy.test.js +127 -99
- package/build/tests/e2e.deploy.test.js.map +1 -1
- package/build/tests/e2e.redis.test.d.ts +2 -0
- package/build/tests/e2e.redis.test.d.ts.map +1 -0
- package/build/tests/e2e.redis.test.js +118 -0
- package/build/tests/e2e.redis.test.js.map +1 -0
- package/build/tests/utils.d.ts +7 -1
- package/build/tests/utils.d.ts.map +1 -1
- package/build/tests/utils.js +17 -6
- package/build/tests/utils.js.map +1 -1
- package/build/ts/app.module.d.ts.map +1 -1
- package/build/ts/app.module.js +6 -0
- package/build/ts/app.module.js.map +1 -1
- package/build/ts/common/__tests__/common.test.js +44 -46
- package/build/ts/common/__tests__/common.test.js.map +1 -1
- package/build/ts/common/accountAbstraction.d.ts +7 -24
- package/build/ts/common/accountAbstraction.d.ts.map +1 -1
- package/build/ts/common/accountAbstraction.js +22 -49
- package/build/ts/common/accountAbstraction.js.map +1 -1
- package/build/ts/common/chain.d.ts +22 -0
- package/build/ts/common/chain.d.ts.map +1 -0
- package/build/ts/common/chain.js +37 -0
- package/build/ts/common/chain.js.map +1 -0
- package/build/ts/common/coordinatorKeypair.d.ts +7 -0
- package/build/ts/common/coordinatorKeypair.d.ts.map +1 -0
- package/build/ts/common/coordinatorKeypair.js +14 -0
- package/build/ts/common/coordinatorKeypair.js.map +1 -0
- package/build/ts/common/errors.d.ts +11 -8
- package/build/ts/common/errors.d.ts.map +1 -1
- package/build/ts/common/errors.js +10 -7
- package/build/ts/common/errors.js.map +1 -1
- package/build/ts/common/index.d.ts +2 -1
- package/build/ts/common/index.d.ts.map +1 -1
- package/build/ts/common/index.js +2 -1
- package/build/ts/common/index.js.map +1 -1
- package/build/ts/common/networks.d.ts +2 -21
- package/build/ts/common/networks.d.ts.map +1 -1
- package/build/ts/common/networks.js +39 -48
- package/build/ts/common/networks.js.map +1 -1
- package/build/ts/common/types.d.ts +2 -3
- package/build/ts/common/types.d.ts.map +1 -1
- package/build/ts/deployer/__tests__/deployer.controller.test.js +23 -25
- package/build/ts/deployer/__tests__/deployer.controller.test.js.map +1 -1
- package/build/ts/deployer/__tests__/deployer.service.test.js +181 -336
- package/build/ts/deployer/__tests__/deployer.service.test.js.map +1 -1
- package/build/ts/deployer/__tests__/utils.d.ts +31 -6
- package/build/ts/deployer/__tests__/utils.d.ts.map +1 -1
- package/build/ts/deployer/__tests__/utils.js +46 -15
- package/build/ts/deployer/__tests__/utils.js.map +1 -1
- package/build/ts/deployer/deployer.service.d.ts +24 -51
- package/build/ts/deployer/deployer.service.d.ts.map +1 -1
- package/build/ts/deployer/deployer.service.js +334 -468
- package/build/ts/deployer/deployer.service.js.map +1 -1
- package/build/ts/deployer/dto.d.ts +7 -7
- package/build/ts/deployer/dto.d.ts.map +1 -1
- package/build/ts/deployer/dto.js +14 -6
- package/build/ts/deployer/dto.js.map +1 -1
- package/build/ts/deployer/types.d.ts +78 -41
- package/build/ts/deployer/types.d.ts.map +1 -1
- package/build/ts/file/__tests__/file.service.test.js +12 -11
- package/build/ts/file/__tests__/file.service.test.js.map +1 -1
- package/build/ts/file/file.service.d.ts +4 -3
- package/build/ts/file/file.service.d.ts.map +1 -1
- package/build/ts/file/file.service.js +16 -10
- package/build/ts/file/file.service.js.map +1 -1
- package/build/ts/file/types.d.ts +2 -2
- package/build/ts/file/types.d.ts.map +1 -1
- package/build/ts/health/__tests__/health.controller.test.d.ts +2 -0
- package/build/ts/health/__tests__/health.controller.test.d.ts.map +1 -0
- package/build/ts/health/__tests__/health.controller.test.js +52 -0
- package/build/ts/health/__tests__/health.controller.test.js.map +1 -0
- package/build/ts/health/__tests__/health.service.test.d.ts +2 -0
- package/build/ts/health/__tests__/health.service.test.d.ts.map +1 -0
- package/build/ts/health/__tests__/health.service.test.js +101 -0
- package/build/ts/health/__tests__/health.service.test.js.map +1 -0
- package/build/ts/health/health.controller.d.ts +16 -0
- package/build/ts/health/health.controller.d.ts.map +1 -0
- package/build/ts/health/health.controller.js +43 -0
- package/build/ts/health/health.controller.js.map +1 -0
- package/build/ts/health/health.module.d.ts +3 -0
- package/build/ts/health/health.module.d.ts.map +1 -0
- package/build/ts/health/health.module.js +22 -0
- package/build/ts/health/health.module.js.map +1 -0
- package/build/ts/health/health.service.d.ts +42 -0
- package/build/ts/health/health.service.d.ts.map +1 -0
- package/build/ts/health/health.service.js +176 -0
- package/build/ts/health/health.service.js.map +1 -0
- package/build/ts/health/types.d.ts +87 -0
- package/build/ts/health/types.d.ts.map +1 -0
- package/build/ts/health/types.js +2 -0
- package/build/ts/health/types.js.map +1 -0
- package/build/ts/jest/__mocks__/@openzeppelin/merkle-tree.d.ts +11 -0
- package/build/ts/jest/__mocks__/@openzeppelin/merkle-tree.d.ts.map +1 -0
- package/build/ts/jest/__mocks__/@openzeppelin/merkle-tree.js +12 -0
- package/build/ts/jest/__mocks__/@openzeppelin/merkle-tree.js.map +1 -0
- package/build/ts/proof/__tests__/proof.controller.test.js +6 -5
- package/build/ts/proof/__tests__/proof.controller.test.js.map +1 -1
- package/build/ts/proof/__tests__/proof.gateway.test.js +5 -3
- package/build/ts/proof/__tests__/proof.gateway.test.js.map +1 -1
- package/build/ts/proof/__tests__/proof.service.test.js +27 -71
- package/build/ts/proof/__tests__/proof.service.test.js.map +1 -1
- package/build/ts/proof/dto.d.ts +15 -18
- package/build/ts/proof/dto.d.ts.map +1 -1
- package/build/ts/proof/dto.js +55 -49
- package/build/ts/proof/dto.js.map +1 -1
- package/build/ts/proof/proof.controller.d.ts +3 -2
- package/build/ts/proof/proof.controller.d.ts.map +1 -1
- package/build/ts/proof/proof.controller.js +1 -4
- package/build/ts/proof/proof.controller.js.map +1 -1
- package/build/ts/proof/proof.module.d.ts.map +1 -1
- package/build/ts/proof/proof.module.js +1 -0
- package/build/ts/proof/proof.module.js.map +1 -1
- package/build/ts/proof/proof.service.d.ts +4 -6
- package/build/ts/proof/proof.service.d.ts.map +1 -1
- package/build/ts/proof/proof.service.js +48 -130
- package/build/ts/proof/proof.service.js.map +1 -1
- package/build/ts/proof/types.d.ts +21 -17
- package/build/ts/proof/types.d.ts.map +1 -1
- package/build/ts/proof/types.js.map +1 -1
- package/build/ts/redis/__tests__/redis.service.test.d.ts +2 -0
- package/build/ts/redis/__tests__/redis.service.test.d.ts.map +1 -0
- package/build/ts/redis/__tests__/redis.service.test.js +148 -0
- package/build/ts/redis/__tests__/redis.service.test.js.map +1 -0
- package/build/ts/redis/redis.module.d.ts +3 -0
- package/build/ts/redis/redis.module.d.ts.map +1 -0
- package/build/ts/redis/redis.module.js +18 -0
- package/build/ts/redis/redis.module.js.map +1 -0
- package/build/ts/redis/redis.service.d.ts +53 -0
- package/build/ts/redis/redis.service.d.ts.map +1 -0
- package/build/ts/redis/redis.service.js +99 -0
- package/build/ts/redis/redis.service.js.map +1 -0
- package/build/ts/redis/types.d.ts +66 -0
- package/build/ts/redis/types.d.ts.map +1 -0
- package/build/ts/redis/types.js +2 -0
- package/build/ts/redis/types.js.map +1 -0
- package/build/ts/redis/utils.d.ts +20 -0
- package/build/ts/redis/utils.d.ts.map +1 -0
- package/build/ts/redis/utils.js +27 -0
- package/build/ts/redis/utils.js.map +1 -0
- package/build/ts/scheduler/__tests__/scheduler.controller.test.d.ts +2 -0
- package/build/ts/scheduler/__tests__/scheduler.controller.test.d.ts.map +1 -0
- package/build/ts/scheduler/__tests__/scheduler.controller.test.js +62 -0
- package/build/ts/scheduler/__tests__/scheduler.controller.test.js.map +1 -0
- package/build/ts/scheduler/__tests__/scheduler.service.test.d.ts +2 -0
- package/build/ts/scheduler/__tests__/scheduler.service.test.d.ts.map +1 -0
- package/build/ts/scheduler/__tests__/scheduler.service.test.js +369 -0
- package/build/ts/scheduler/__tests__/scheduler.service.test.js.map +1 -0
- package/build/ts/scheduler/dto.d.ts +41 -0
- package/build/ts/scheduler/dto.d.ts.map +1 -0
- package/build/ts/scheduler/dto.js +115 -0
- package/build/ts/scheduler/dto.js.map +1 -0
- package/build/ts/scheduler/scheduler.controller.d.ts +32 -0
- package/build/ts/scheduler/scheduler.controller.d.ts.map +1 -0
- package/build/ts/scheduler/scheduler.controller.js +111 -0
- package/build/ts/scheduler/scheduler.controller.js.map +1 -0
- package/build/ts/scheduler/scheduler.module.d.ts +3 -0
- package/build/ts/scheduler/scheduler.module.d.ts.map +1 -0
- package/build/ts/scheduler/scheduler.module.js +24 -0
- package/build/ts/scheduler/scheduler.module.js.map +1 -0
- package/build/ts/scheduler/scheduler.service.d.ts +71 -0
- package/build/ts/scheduler/scheduler.service.d.ts.map +1 -0
- package/build/ts/scheduler/scheduler.service.js +297 -0
- package/build/ts/scheduler/scheduler.service.js.map +1 -0
- package/build/ts/scheduler/types.d.ts +65 -0
- package/build/ts/scheduler/types.d.ts.map +1 -0
- package/build/ts/scheduler/types.js +2 -0
- package/build/ts/scheduler/types.js.map +1 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.js +2 -2
- package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.js.map +1 -1
- package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.js +34 -19
- package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.js.map +1 -1
- package/build/ts/sessionKeys/__tests__/utils.d.ts +1 -1
- package/build/ts/sessionKeys/__tests__/utils.d.ts.map +1 -1
- package/build/ts/sessionKeys/__tests__/utils.js +7 -6
- package/build/ts/sessionKeys/__tests__/utils.js.map +1 -1
- package/build/ts/sessionKeys/provider/KernelEIP1193Provider.d.ts +53 -0
- package/build/ts/sessionKeys/provider/KernelEIP1193Provider.d.ts.map +1 -0
- package/build/ts/sessionKeys/provider/KernelEIP1193Provider.js +105 -0
- package/build/ts/sessionKeys/provider/KernelEIP1193Provider.js.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.service.d.ts +16 -4
- package/build/ts/sessionKeys/sessionKeys.service.d.ts.map +1 -1
- package/build/ts/sessionKeys/sessionKeys.service.js +23 -6
- package/build/ts/sessionKeys/sessionKeys.service.js.map +1 -1
- package/build/ts/subgraph/__tests__/subgraph.controller.test.js +2 -2
- package/build/ts/subgraph/__tests__/subgraph.controller.test.js.map +1 -1
- package/build/ts/subgraph/__tests__/subgraph.gateway.test.js +2 -2
- package/build/ts/subgraph/__tests__/subgraph.gateway.test.js.map +1 -1
- package/build/ts/subgraph/__tests__/subgraph.service.test.js +5 -5
- package/build/ts/subgraph/__tests__/subgraph.service.test.js.map +1 -1
- package/build/ts/subgraph/dto.d.ts +2 -2
- package/build/ts/subgraph/dto.d.ts.map +1 -1
- package/build/ts/subgraph/dto.js +3 -3
- package/build/ts/subgraph/dto.js.map +1 -1
- package/build/ts/subgraph/subgraph.service.d.ts +4 -0
- package/build/ts/subgraph/subgraph.service.d.ts.map +1 -1
- package/build/ts/subgraph/subgraph.service.js +23 -10
- package/build/ts/subgraph/subgraph.service.js.map +1 -1
- package/build/ts/subgraph/types.d.ts +2 -2
- package/build/ts/subgraph/types.d.ts.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +45 -38
- package/build/tests/e2e.aa.test.d.ts +0 -2
- package/build/tests/e2e.aa.test.d.ts.map +0 -1
- package/build/tests/e2e.aa.test.js +0 -103
- package/build/tests/e2e.aa.test.js.map +0 -1
- package/build/ts/deployer/utils.d.ts +0 -8
- package/build/ts/deployer/utils.d.ts.map +0 -1
- package/build/ts/deployer/utils.js +0 -9
- package/build/ts/deployer/utils.js.map +0 -1
|
@@ -7,29 +7,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
import {
|
|
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, VerifyingKeysRegistry__factory as VerifyingKeysRegistryFactory, 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, extractAllVerifyingKeys, extractVerifyingKey, generateEmptyBallotRoots, } from "@maci-protocol/sdk";
|
|
13
|
-
import { Injectable, Logger } from "@nestjs/common";
|
|
10
|
+
import { ContractStorage, EPolicies, VerifyingKeysRegistry__factory as VerifyingKeysRegistryFactory, MessageProcessor__factory as MessageProcessorFactory, Tally__factory as TallyFactory, Poll__factory as PollFactory, MACI__factory as MACIFactory, EContracts, EInitialVoiceCreditProxies, EMode, deployPoll, extractAllVerifyingKeys, deployConstantInitialVoiceCreditProxy, deployFreeForAllSignUpPolicy, deployERC20VotesPolicy, deployAnonAadhaarPolicy, deploySignupTokenPolicy, deployMerkleProofPolicy, deploySemaphoreSignupPolicy, deployZupassSignUpPolicy, deployGitcoinPassportPolicy, deployEASSignUpPolicy, deployHatsSignupPolicy, deployMaci, setVerifyingKeys, deployVerifyingKeysRegistryContract, generateEmptyBallotRoots, getDeployedPolicyProxyFactories, deployVerifier, ECheckerFactories, EPolicyFactories, deployConstantInitialVoiceCreditProxyFactory, EInitialVoiceCreditProxiesFactories, } from "@maci-protocol/sdk";
|
|
11
|
+
import { Injectable } from "@nestjs/common";
|
|
14
12
|
import { BaseContract } from "ethers";
|
|
15
|
-
import { encodeFunctionData } from "viem";
|
|
16
|
-
import path from "path";
|
|
17
13
|
import { ErrorCodes } from "../common";
|
|
18
|
-
import {
|
|
14
|
+
import { getCoordinatorKeypair } from "../common/coordinatorKeypair";
|
|
19
15
|
import { FileService } from "../file/file.service";
|
|
20
16
|
import { SessionKeysService } from "../sessionKeys/sessionKeys.service";
|
|
21
|
-
import { MAX_GAS_LIMIT } from "./constants";
|
|
22
|
-
import { estimateExtraGasLimit } from "./utils";
|
|
23
17
|
/**
|
|
24
18
|
* DeployerService is responsible for deploying contracts.
|
|
25
19
|
*/
|
|
26
|
-
let DeployerService =
|
|
20
|
+
let DeployerService = class DeployerService {
|
|
27
21
|
sessionKeysService;
|
|
28
22
|
fileService;
|
|
29
|
-
/**
|
|
30
|
-
* Logger
|
|
31
|
-
*/
|
|
32
|
-
logger = new Logger(DeployerService_1.name);
|
|
33
23
|
/**
|
|
34
24
|
* Contract storage instance
|
|
35
25
|
*/
|
|
@@ -42,280 +32,290 @@ let DeployerService = DeployerService_1 = class DeployerService {
|
|
|
42
32
|
constructor(sessionKeysService, fileService) {
|
|
43
33
|
this.sessionKeysService = sessionKeysService;
|
|
44
34
|
this.fileService = fileService;
|
|
45
|
-
this.
|
|
46
|
-
this.storage = ContractStorage.getInstance(path.join(process.cwd(), "deployed-contracts.json"));
|
|
35
|
+
this.storage = ContractStorage.getInstance();
|
|
47
36
|
}
|
|
48
37
|
/**
|
|
49
|
-
* Get the policy
|
|
50
|
-
*
|
|
38
|
+
* Get the policy contract object
|
|
39
|
+
* always deploy and save it
|
|
51
40
|
*
|
|
52
|
-
* @param
|
|
41
|
+
* @param signer - the signer
|
|
53
42
|
* @param network - the network
|
|
54
|
-
* @param
|
|
55
|
-
* @returns - the policy
|
|
43
|
+
* @param policyConfig - the policy configuration parameters
|
|
44
|
+
* @returns - the policy contract
|
|
56
45
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
let
|
|
60
|
-
let
|
|
46
|
+
async deployAndSavePolicy(signer, network, policyConfig) {
|
|
47
|
+
let policyContract;
|
|
48
|
+
let checkerContract;
|
|
49
|
+
let policyFactory;
|
|
50
|
+
let checkFactory;
|
|
51
|
+
let policyFactoryName;
|
|
52
|
+
let checkFactoryName;
|
|
53
|
+
let factoryIsSaved;
|
|
54
|
+
let checkerIsSaved;
|
|
55
|
+
const { policyType, checkerType, args } = policyConfig;
|
|
61
56
|
// based on the policy type, we need to deploy the correct policy
|
|
62
57
|
switch (policyType) {
|
|
63
58
|
case EPolicies.FreeForAll: {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
59
|
+
policyFactoryName = EPolicyFactories.FreeForAll;
|
|
60
|
+
checkFactoryName = ECheckerFactories.FreeForAll;
|
|
61
|
+
const factories = await getDeployedPolicyProxyFactories({
|
|
62
|
+
policy: policyFactoryName,
|
|
63
|
+
checker: checkFactoryName,
|
|
64
|
+
network,
|
|
65
|
+
signer,
|
|
66
|
+
});
|
|
67
|
+
factoryIsSaved = !!factories.policy;
|
|
68
|
+
checkerIsSaved = !!factories.checker;
|
|
69
|
+
[policyContract, checkerContract, policyFactory, checkFactory] = await deployFreeForAllSignUpPolicy(factories, signer, true);
|
|
70
|
+
break;
|
|
70
71
|
}
|
|
71
72
|
case EPolicies.EAS: {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
73
|
+
policyFactoryName = EPolicyFactories.EAS;
|
|
74
|
+
checkFactoryName = ECheckerFactories.EAS;
|
|
75
|
+
const factories = await getDeployedPolicyProxyFactories({
|
|
76
|
+
policy: policyFactoryName,
|
|
77
|
+
checker: checkFactoryName,
|
|
78
|
+
network,
|
|
79
|
+
signer,
|
|
80
|
+
});
|
|
81
|
+
factoryIsSaved = !!factories.policy;
|
|
82
|
+
checkerIsSaved = !!factories.checker;
|
|
83
|
+
[policyContract, checkerContract, policyFactory, checkFactory] = await deployEASSignUpPolicy({
|
|
84
|
+
eas: args.easAddress,
|
|
85
|
+
attester: args.attester,
|
|
86
|
+
schema: args.schema,
|
|
87
|
+
}, factories, signer, true);
|
|
88
|
+
break;
|
|
85
89
|
}
|
|
86
|
-
case EPolicies.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
};
|
|
90
|
+
case EPolicies.GitcoinPassport: {
|
|
91
|
+
policyFactoryName = EPolicyFactories.GitcoinPassport;
|
|
92
|
+
checkFactoryName = ECheckerFactories.GitcoinPassport;
|
|
93
|
+
const factories = await getDeployedPolicyProxyFactories({
|
|
94
|
+
policy: policyFactoryName,
|
|
95
|
+
checker: checkFactoryName,
|
|
96
|
+
network,
|
|
97
|
+
signer,
|
|
98
|
+
});
|
|
99
|
+
factoryIsSaved = !!factories.policy;
|
|
100
|
+
checkerIsSaved = !!factories.checker;
|
|
101
|
+
[policyContract, checkerContract, policyFactory, checkFactory] = await deployGitcoinPassportPolicy({
|
|
102
|
+
decoderAddress: args.decoderAddress,
|
|
103
|
+
minimumScore: Number(args.passingScore),
|
|
104
|
+
}, factories, signer, true);
|
|
105
|
+
break;
|
|
101
106
|
}
|
|
102
107
|
case EPolicies.Hats: {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
108
|
+
policyFactoryName = EPolicyFactories.Hats;
|
|
109
|
+
checkFactoryName = ECheckerFactories.Hats;
|
|
110
|
+
const factories = await getDeployedPolicyProxyFactories({
|
|
111
|
+
policy: policyFactoryName,
|
|
112
|
+
checker: checkFactoryName,
|
|
113
|
+
network,
|
|
114
|
+
signer,
|
|
115
|
+
});
|
|
116
|
+
factoryIsSaved = !!factories.policy;
|
|
117
|
+
checkerIsSaved = !!factories.checker;
|
|
118
|
+
[policyContract, checkerContract, policyFactory, checkFactory] = await deployHatsSignupPolicy({
|
|
119
|
+
hats: args.hatsProtocolAddress,
|
|
120
|
+
criterionHats: args.critrionHats.map((c) => BigInt(c)),
|
|
121
|
+
}, factories, signer, true);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
case EPolicies.Zupass: {
|
|
125
|
+
policyFactoryName = EPolicyFactories.Zupass;
|
|
126
|
+
checkFactoryName = ECheckerFactories.Zupass;
|
|
127
|
+
const factories = await getDeployedPolicyProxyFactories({
|
|
128
|
+
policy: policyFactoryName,
|
|
129
|
+
checker: checkFactoryName,
|
|
130
|
+
network,
|
|
131
|
+
signer,
|
|
132
|
+
});
|
|
133
|
+
factoryIsSaved = !!factories.policy;
|
|
134
|
+
checkerIsSaved = !!factories.checker;
|
|
135
|
+
[policyContract, checkerContract, policyFactory, checkFactory] = await deployZupassSignUpPolicy({
|
|
136
|
+
eventId: args.eventId,
|
|
137
|
+
signer1: args.signer1,
|
|
138
|
+
signer2: args.signer2,
|
|
139
|
+
verifier: args.zupassVerifier,
|
|
140
|
+
}, factories, signer, true);
|
|
141
|
+
break;
|
|
115
142
|
}
|
|
116
143
|
case EPolicies.Semaphore: {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
144
|
+
policyFactoryName = EPolicyFactories.Semaphore;
|
|
145
|
+
checkFactoryName = ECheckerFactories.Semaphore;
|
|
146
|
+
const factories = await getDeployedPolicyProxyFactories({
|
|
147
|
+
policy: policyFactoryName,
|
|
148
|
+
checker: checkFactoryName,
|
|
149
|
+
network,
|
|
150
|
+
signer,
|
|
151
|
+
});
|
|
152
|
+
factoryIsSaved = !!factories.policy;
|
|
153
|
+
checkerIsSaved = !!factories.checker;
|
|
154
|
+
[policyContract, checkerContract, policyFactory, checkFactory] = await deploySemaphoreSignupPolicy({
|
|
155
|
+
semaphore: args.semaphoreContract,
|
|
156
|
+
groupId: BigInt(args.groupId),
|
|
157
|
+
}, factories, signer, true);
|
|
158
|
+
break;
|
|
129
159
|
}
|
|
130
|
-
case EPolicies.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
160
|
+
case EPolicies.MerkleProof: {
|
|
161
|
+
policyFactoryName = EPolicyFactories.MerkleProof;
|
|
162
|
+
checkFactoryName = ECheckerFactories.MerkleProof;
|
|
163
|
+
const factories = await getDeployedPolicyProxyFactories({
|
|
164
|
+
policy: policyFactoryName,
|
|
165
|
+
checker: checkFactoryName,
|
|
166
|
+
network,
|
|
167
|
+
signer,
|
|
168
|
+
});
|
|
169
|
+
factoryIsSaved = !!factories.policy;
|
|
170
|
+
checkerIsSaved = !!factories.checker;
|
|
171
|
+
[policyContract, checkerContract, policyFactory, checkFactory] = await deployMerkleProofPolicy({
|
|
172
|
+
root: args.root,
|
|
173
|
+
}, factories, signer, true);
|
|
174
|
+
break;
|
|
143
175
|
}
|
|
144
|
-
case EPolicies.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
};
|
|
176
|
+
case EPolicies.Token: {
|
|
177
|
+
policyFactoryName = EPolicyFactories.Token;
|
|
178
|
+
checkFactoryName = ECheckerFactories.Token;
|
|
179
|
+
const factories = await getDeployedPolicyProxyFactories({
|
|
180
|
+
policy: policyFactoryName,
|
|
181
|
+
checker: checkFactoryName,
|
|
182
|
+
network,
|
|
183
|
+
signer,
|
|
184
|
+
});
|
|
185
|
+
factoryIsSaved = !!factories.policy;
|
|
186
|
+
checkerIsSaved = !!factories.checker;
|
|
187
|
+
[policyContract, checkerContract, policyFactory, checkFactory] = await deploySignupTokenPolicy({
|
|
188
|
+
token: args.token,
|
|
189
|
+
}, factories, signer, true);
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
case EPolicies.AnonAadhaar: {
|
|
193
|
+
policyFactoryName = EPolicyFactories.AnonAadhaar;
|
|
194
|
+
checkFactoryName = ECheckerFactories.AnonAadhaar;
|
|
195
|
+
const factories = await getDeployedPolicyProxyFactories({
|
|
196
|
+
policy: policyFactoryName,
|
|
197
|
+
checker: checkFactoryName,
|
|
198
|
+
network,
|
|
199
|
+
signer,
|
|
200
|
+
});
|
|
201
|
+
factoryIsSaved = !!factories.policy;
|
|
202
|
+
checkerIsSaved = !!factories.checker;
|
|
203
|
+
[policyContract, checkerContract, policyFactory, checkFactory] = await deployAnonAadhaarPolicy({
|
|
204
|
+
verifierAddress: args.verifier,
|
|
205
|
+
nullifierSeed: args.nullifierSeed,
|
|
206
|
+
}, factories, signer, true);
|
|
207
|
+
break;
|
|
158
208
|
}
|
|
159
|
-
case EPolicies.
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
209
|
+
case EPolicies.ERC20Votes: {
|
|
210
|
+
policyFactoryName = EPolicyFactories.ERC20Votes;
|
|
211
|
+
checkFactoryName = ECheckerFactories.ERC20Votes;
|
|
212
|
+
const factories = await getDeployedPolicyProxyFactories({
|
|
213
|
+
policy: policyFactoryName,
|
|
214
|
+
checker: checkFactoryName,
|
|
215
|
+
network,
|
|
216
|
+
signer,
|
|
217
|
+
});
|
|
218
|
+
factoryIsSaved = !!factories.policy;
|
|
219
|
+
checkerIsSaved = !!factories.checker;
|
|
220
|
+
[policyContract, checkerContract, policyFactory, checkFactory] = await deployERC20VotesPolicy({
|
|
221
|
+
snapshotBlock: BigInt(args.snapshotBlock),
|
|
222
|
+
threshold: BigInt(args.threshold),
|
|
223
|
+
token: args.token,
|
|
224
|
+
}, factories, signer, true);
|
|
225
|
+
break;
|
|
172
226
|
}
|
|
173
227
|
default:
|
|
174
228
|
throw new Error(ErrorCodes.UNSUPPORTED_POLICY.toString());
|
|
175
229
|
}
|
|
230
|
+
await this.storage.register({
|
|
231
|
+
id: policyType,
|
|
232
|
+
name: policyType,
|
|
233
|
+
contract: policyContract,
|
|
234
|
+
args: [await checkerContract.getAddress()],
|
|
235
|
+
network,
|
|
236
|
+
});
|
|
237
|
+
await this.storage.register({
|
|
238
|
+
id: checkerType,
|
|
239
|
+
name: checkerType,
|
|
240
|
+
contract: checkerContract,
|
|
241
|
+
args: args ? Object.values(args).map((arg) => String(arg)) : [],
|
|
242
|
+
network,
|
|
243
|
+
});
|
|
244
|
+
if (!factoryIsSaved) {
|
|
245
|
+
await this.storage.register({
|
|
246
|
+
id: policyFactoryName,
|
|
247
|
+
name: policyFactoryName,
|
|
248
|
+
contract: policyFactory,
|
|
249
|
+
network,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
if (!checkerIsSaved) {
|
|
253
|
+
await this.storage.register({
|
|
254
|
+
id: checkFactoryName,
|
|
255
|
+
name: checkFactoryName,
|
|
256
|
+
contract: checkFactory,
|
|
257
|
+
network,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
return policyContract;
|
|
176
261
|
}
|
|
177
262
|
/**
|
|
178
|
-
* Get the voice credit proxy
|
|
179
|
-
*
|
|
263
|
+
* Get the voice credit proxy factory contract object
|
|
264
|
+
* always deploy and save it
|
|
180
265
|
*
|
|
181
|
-
* @param
|
|
266
|
+
* @param signer - the signer
|
|
267
|
+
* @param voiceCreditProxyFactoryType - the voice credit proxy factory type
|
|
182
268
|
* @param network - the network
|
|
183
|
-
* @
|
|
184
|
-
* @returns - the voice credit proxy abi and bytecode
|
|
269
|
+
* @returns - the voice credit proxy factory contract
|
|
185
270
|
*/
|
|
186
|
-
|
|
187
|
-
let
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
};
|
|
271
|
+
async deployAndSaveVoiceCreditProxyFactory(signer, voiceCreditProxyFactoryType, network) {
|
|
272
|
+
let contract;
|
|
273
|
+
switch (voiceCreditProxyFactoryType) {
|
|
274
|
+
case EInitialVoiceCreditProxiesFactories.Constant: {
|
|
275
|
+
contract = await deployConstantInitialVoiceCreditProxyFactory(signer, true);
|
|
276
|
+
break;
|
|
200
277
|
}
|
|
201
278
|
default:
|
|
202
|
-
throw new Error(ErrorCodes.
|
|
279
|
+
throw new Error(ErrorCodes.UNSUPPORTED_VOICE_CREDIT_PROXY_FACTORY.toString());
|
|
203
280
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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,
|
|
281
|
+
this.storage.register({
|
|
282
|
+
id: voiceCreditProxyFactoryType,
|
|
283
|
+
contract,
|
|
284
|
+
args: [],
|
|
285
|
+
network,
|
|
234
286
|
});
|
|
235
|
-
|
|
236
|
-
hash: tx,
|
|
237
|
-
});
|
|
238
|
-
const txReceipt = await publicClient.getTransactionReceipt({
|
|
239
|
-
hash: receipt.receipt.transactionHash,
|
|
240
|
-
});
|
|
241
|
-
return getDeployedContractAddress(txReceipt);
|
|
287
|
+
return contract;
|
|
242
288
|
}
|
|
243
289
|
/**
|
|
244
|
-
*
|
|
290
|
+
* Get the voice credit proxy contract object
|
|
291
|
+
* always deploy and save it
|
|
245
292
|
*
|
|
246
|
-
* @param
|
|
293
|
+
* @param signer - the signer
|
|
294
|
+
* @param voiceCreditProxyType - the voice credit proxy type
|
|
295
|
+
* @param network - the network
|
|
296
|
+
* @param initialVoiceCreditProxyFactory - the initial voice credit proxy factory
|
|
247
297
|
* @param args - the args
|
|
248
|
-
* @
|
|
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
|
|
298
|
+
* @returns - the voice credit proxy contract
|
|
254
299
|
*/
|
|
255
|
-
async
|
|
256
|
-
let
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
300
|
+
async deployAndSaveVoiceCreditProxy(signer, voiceCreditProxyType, network, initialVoiceCreditProxyFactory, args) {
|
|
301
|
+
let contract;
|
|
302
|
+
switch (voiceCreditProxyType) {
|
|
303
|
+
case EInitialVoiceCreditProxies.Constant: {
|
|
304
|
+
contract = await deployConstantInitialVoiceCreditProxy({
|
|
305
|
+
amount: args.amount,
|
|
306
|
+
}, initialVoiceCreditProxyFactory, signer);
|
|
307
|
+
break;
|
|
262
308
|
}
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
});
|
|
309
|
+
default:
|
|
310
|
+
throw new Error(ErrorCodes.UNSUPPORTED_VOICE_CREDIT_PROXY.toString());
|
|
274
311
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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,
|
|
312
|
+
await this.storage.register({
|
|
313
|
+
id: voiceCreditProxyType,
|
|
314
|
+
contract,
|
|
315
|
+
args: args ? Object.values(args).map((arg) => String(arg)) : [],
|
|
316
|
+
network,
|
|
313
317
|
});
|
|
314
|
-
|
|
315
|
-
if (!receipt.success) {
|
|
316
|
-
throw new Error(errorMessage);
|
|
317
|
-
}
|
|
318
|
-
return receipt;
|
|
318
|
+
return contract;
|
|
319
319
|
}
|
|
320
320
|
/**
|
|
321
321
|
* Get verifying keys arguments (specially zkey paths)
|
|
@@ -325,31 +325,41 @@ let DeployerService = DeployerService_1 = class DeployerService {
|
|
|
325
325
|
* @param mode - use QV or NON_QV
|
|
326
326
|
* @returns SetVerifyingKeysArgs
|
|
327
327
|
*/
|
|
328
|
-
async getVerifyingKeysArgs(signer,
|
|
329
|
-
const pollJoiningZkeyPath = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_POLL_JOINING_ZKEY_NAME
|
|
330
|
-
const pollJoinedZkeyPath = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_POLL_JOINED_ZKEY_NAME
|
|
331
|
-
const
|
|
332
|
-
const tallyVotesZkeyPath = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_TALLY_ZKEY_NAME, mode === EMode.QV).zkey;
|
|
333
|
-
const { pollJoiningVerifyingKey, pollJoinedVerifyingKey, processVerifyingKey, tallyVerifyingKey } = await extractAllVerifyingKeys({
|
|
328
|
+
async getVerifyingKeysArgs(signer, verifyingKeysRegistryAddress, verifyingKeysRegistryArgs, modes) {
|
|
329
|
+
const { zkey: pollJoiningZkeyPath } = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_POLL_JOINING_ZKEY_NAME);
|
|
330
|
+
const { zkey: pollJoinedZkeyPath } = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_POLL_JOINED_ZKEY_NAME);
|
|
331
|
+
const { pollJoiningVerifyingKey, pollJoinedVerifyingKey } = await extractAllVerifyingKeys({
|
|
334
332
|
pollJoiningZkeyPath,
|
|
335
333
|
pollJoinedZkeyPath,
|
|
336
|
-
processMessagesZkeyPath,
|
|
337
|
-
tallyVotesZkeyPath,
|
|
338
334
|
});
|
|
339
|
-
const
|
|
335
|
+
const processAndTallyVerifyingKeys = await Promise.all(modes.map(async (mode) => {
|
|
336
|
+
const { zkey: messageProcessorZkeyPath } = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_MESSAGE_PROCESS_ZKEY_NAME, mode);
|
|
337
|
+
// There are only QV and Non-QV modes available for tally circuit
|
|
338
|
+
const { zkey: voteTallyZkeyPath } = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_TALLY_ZKEY_NAME,
|
|
339
|
+
// if FULL use NON_QV because there are only VoteTallyQV and VoteTallyNonQV zkeys
|
|
340
|
+
mode === EMode.FULL ? EMode.NON_QV : mode);
|
|
341
|
+
const { processVerifyingKey, tallyVerifyingKey } = await extractAllVerifyingKeys({
|
|
342
|
+
messageProcessorZkeyPath,
|
|
343
|
+
voteTallyZkeyPath,
|
|
344
|
+
});
|
|
345
|
+
return { processVerifyingKey: processVerifyingKey, tallyVerifyingKey: tallyVerifyingKey };
|
|
346
|
+
}));
|
|
347
|
+
const processVerifyingKeys = processAndTallyVerifyingKeys.map((item) => item.processVerifyingKey);
|
|
348
|
+
const tallyVerifyingKeys = processAndTallyVerifyingKeys.map((item) => item.tallyVerifyingKey);
|
|
349
|
+
const { stateTreeDepth, pollStateTreeDepth, tallyProcessingStateTreeDepth, voteOptionTreeDepth, messageBatchSize } = verifyingKeysRegistryArgs;
|
|
340
350
|
return {
|
|
341
351
|
pollJoiningVerifyingKey: pollJoiningVerifyingKey,
|
|
342
352
|
pollJoinedVerifyingKey: pollJoinedVerifyingKey,
|
|
343
|
-
|
|
344
|
-
|
|
353
|
+
processMessagesVerifyingKeys: processVerifyingKeys,
|
|
354
|
+
tallyVotesVerifyingKeys: tallyVerifyingKeys,
|
|
345
355
|
stateTreeDepth: Number(stateTreeDepth),
|
|
346
|
-
|
|
356
|
+
tallyProcessingStateTreeDepth: Number(tallyProcessingStateTreeDepth),
|
|
347
357
|
voteOptionTreeDepth: Number(voteOptionTreeDepth),
|
|
348
358
|
messageBatchSize: Number(messageBatchSize),
|
|
349
359
|
pollStateTreeDepth: Number(pollStateTreeDepth),
|
|
350
360
|
signer,
|
|
351
|
-
|
|
352
|
-
verifyingKeysRegistryAddress
|
|
361
|
+
modes,
|
|
362
|
+
verifyingKeysRegistryAddress,
|
|
353
363
|
};
|
|
354
364
|
}
|
|
355
365
|
/**
|
|
@@ -361,165 +371,46 @@ let DeployerService = DeployerService_1 = class DeployerService {
|
|
|
361
371
|
* @returns the address of the deployed maci contract
|
|
362
372
|
*/
|
|
363
373
|
async deployMaci({ approval, sessionKeyAddress, chain, config }) {
|
|
364
|
-
const
|
|
365
|
-
const
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
//
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
"contracts/crypto/PoseidonT4.sol:PoseidonT4": poseidonT4Address,
|
|
405
|
-
"contracts/crypto/PoseidonT5.sol:PoseidonT5": poseidonT5Address,
|
|
406
|
-
"contracts/crypto/PoseidonT6.sol:PoseidonT6": poseidonT6Address,
|
|
407
|
-
}), kernelClient, bundlerClient, publicClient, chain);
|
|
408
|
-
const messageProcessorFactoryAddress = await this.deployAndStore(EContracts.MessageProcessorFactory, [], MessageProcessorFactoryFactory.abi, MessageProcessorFactoryFactory.linkBytecode({
|
|
409
|
-
"contracts/crypto/PoseidonT3.sol:PoseidonT3": poseidonT3Address,
|
|
410
|
-
"contracts/crypto/PoseidonT4.sol:PoseidonT4": poseidonT4Address,
|
|
411
|
-
"contracts/crypto/PoseidonT5.sol:PoseidonT5": poseidonT5Address,
|
|
412
|
-
"contracts/crypto/PoseidonT6.sol:PoseidonT6": poseidonT6Address,
|
|
413
|
-
}), kernelClient, bundlerClient, publicClient, chain);
|
|
414
|
-
// 4. VerifyingKeysRegistry
|
|
415
|
-
const verifyingKeysRegistryAddress = await this.deployAndStore(EContracts.VerifyingKeysRegistry, [], VerifyingKeysRegistryFactory.abi, VerifyingKeysRegistryFactory.bytecode, kernelClient, bundlerClient, publicClient, chain);
|
|
416
|
-
try {
|
|
417
|
-
const processMessagesZkeyPathQv = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_MESSAGE_PROCESS_ZKEY_NAME, true);
|
|
418
|
-
const tallyVotesZkeyPathQv = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_TALLY_ZKEY_NAME, true);
|
|
419
|
-
const processMessagesZkeyPathNonQv = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_MESSAGE_PROCESS_ZKEY_NAME, false);
|
|
420
|
-
const tallyVotesZkeyPathNonQv = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_TALLY_ZKEY_NAME, false);
|
|
421
|
-
const pollJoiningZkeyPath = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_POLL_JOINING_ZKEY_NAME, true);
|
|
422
|
-
const pollJoinedZkeyPath = this.fileService.getZkeyFilePaths(process.env.COORDINATOR_POLL_JOINED_ZKEY_NAME, true);
|
|
423
|
-
const [qvProcessVerifyingKey, qvTallyVerifyingKey, nonQvProcessVerifyingKey, nonQvTallyVerifyingKey, pollJoiningVerifyingKey, pollJoinedVerifyingKey,] = await Promise.all([
|
|
424
|
-
extractVerifyingKey(processMessagesZkeyPathQv.zkey),
|
|
425
|
-
extractVerifyingKey(tallyVotesZkeyPathQv.zkey),
|
|
426
|
-
extractVerifyingKey(processMessagesZkeyPathNonQv.zkey),
|
|
427
|
-
extractVerifyingKey(tallyVotesZkeyPathNonQv.zkey),
|
|
428
|
-
extractVerifyingKey(pollJoiningZkeyPath.zkey),
|
|
429
|
-
extractVerifyingKey(pollJoinedZkeyPath.zkey),
|
|
430
|
-
]).then((verifyingKeys) => verifyingKeys.map((verifyingKey) => verifyingKey && VerifyingKey.fromObj(verifyingKey).asContractParam()));
|
|
431
|
-
const processZkeys = [qvProcessVerifyingKey, nonQvProcessVerifyingKey].filter(Boolean);
|
|
432
|
-
const tallyZkeys = [qvTallyVerifyingKey, nonQvTallyVerifyingKey].filter(Boolean);
|
|
433
|
-
// check if the keys are already set
|
|
434
|
-
const [isProcessVerifyingKeySet, isProcessNonQvVerifyingKeySet, isTallyVerifyingKeySet, isTallyNonQvVerifyingKeySet,] = await Promise.all([
|
|
435
|
-
publicClient.readContract({
|
|
436
|
-
address: verifyingKeysRegistryAddress,
|
|
437
|
-
abi: VerifyingKeysRegistryFactory.abi,
|
|
438
|
-
functionName: "hasProcessVerifyingKey",
|
|
439
|
-
args: [
|
|
440
|
-
config.VerifyingKeysRegistry.args.stateTreeDepth,
|
|
441
|
-
config.VerifyingKeysRegistry.args.voteOptionTreeDepth,
|
|
442
|
-
config.VerifyingKeysRegistry.args.messageBatchSize,
|
|
443
|
-
EMode.QV,
|
|
444
|
-
],
|
|
445
|
-
}),
|
|
446
|
-
publicClient.readContract({
|
|
447
|
-
address: verifyingKeysRegistryAddress,
|
|
448
|
-
abi: VerifyingKeysRegistryFactory.abi,
|
|
449
|
-
functionName: "hasProcessVerifyingKey",
|
|
450
|
-
args: [
|
|
451
|
-
config.VerifyingKeysRegistry.args.stateTreeDepth,
|
|
452
|
-
config.VerifyingKeysRegistry.args.voteOptionTreeDepth,
|
|
453
|
-
config.VerifyingKeysRegistry.args.messageBatchSize,
|
|
454
|
-
EMode.NON_QV,
|
|
455
|
-
],
|
|
456
|
-
}),
|
|
457
|
-
publicClient.readContract({
|
|
458
|
-
address: verifyingKeysRegistryAddress,
|
|
459
|
-
abi: VerifyingKeysRegistryFactory.abi,
|
|
460
|
-
functionName: "hasTallyVerifyingKey",
|
|
461
|
-
args: [
|
|
462
|
-
config.VerifyingKeysRegistry.args.stateTreeDepth,
|
|
463
|
-
config.VerifyingKeysRegistry.args.intStateTreeDepth,
|
|
464
|
-
config.VerifyingKeysRegistry.args.voteOptionTreeDepth,
|
|
465
|
-
EMode.QV,
|
|
466
|
-
],
|
|
467
|
-
}),
|
|
468
|
-
publicClient.readContract({
|
|
469
|
-
address: verifyingKeysRegistryAddress,
|
|
470
|
-
abi: VerifyingKeysRegistryFactory.abi,
|
|
471
|
-
functionName: "hasTallyVerifyingKey",
|
|
472
|
-
args: [
|
|
473
|
-
config.VerifyingKeysRegistry.args.stateTreeDepth,
|
|
474
|
-
config.VerifyingKeysRegistry.args.intStateTreeDepth,
|
|
475
|
-
config.VerifyingKeysRegistry.args.voteOptionTreeDepth,
|
|
476
|
-
EMode.NON_QV,
|
|
477
|
-
],
|
|
478
|
-
}),
|
|
479
|
-
]);
|
|
480
|
-
if (isProcessVerifyingKeySet &&
|
|
481
|
-
isProcessNonQvVerifyingKeySet &&
|
|
482
|
-
isTallyVerifyingKeySet &&
|
|
483
|
-
isTallyNonQvVerifyingKeySet) {
|
|
484
|
-
this.logger.debug("Verifying keys are already set on the verifyingKey registry");
|
|
485
|
-
}
|
|
486
|
-
else {
|
|
487
|
-
await this.estimateGasAndSend(verifyingKeysRegistryAddress, 0n, VerifyingKeysRegistryFactory.abi, "setVerifyingKeysBatch", [
|
|
488
|
-
config.VerifyingKeysRegistry.args.stateTreeDepth,
|
|
489
|
-
config.VerifyingKeysRegistry.args.pollStateTreeDepth,
|
|
490
|
-
config.VerifyingKeysRegistry.args.intStateTreeDepth,
|
|
491
|
-
config.VerifyingKeysRegistry.args.voteOptionTreeDepth,
|
|
492
|
-
config.VerifyingKeysRegistry.args.messageBatchSize,
|
|
493
|
-
[EMode.QV, EMode.NON_QV],
|
|
494
|
-
pollJoiningVerifyingKey,
|
|
495
|
-
pollJoinedVerifyingKey,
|
|
496
|
-
processZkeys,
|
|
497
|
-
tallyZkeys,
|
|
498
|
-
], ErrorCodes.FAILED_TO_SET_VERIFYING_KEYS.toString(), kernelClient, bundlerClient);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
catch (error) {
|
|
502
|
-
this.logger.error("Failed to set verifying keys on verifyingKey registry: ", error);
|
|
503
|
-
throw error;
|
|
504
|
-
}
|
|
505
|
-
// 5. maci (here we don't check whether one is already deployed, we just deploy it)
|
|
506
|
-
const emptyBallotRoots = generateEmptyBallotRoots(config.MACI.stateTreeDepth);
|
|
507
|
-
const maciAddress = await this.deployAndStore(EContracts.MACI, [
|
|
508
|
-
pollFactoryAddress,
|
|
509
|
-
messageProcessorFactoryAddress,
|
|
510
|
-
tallyFactoryAddress,
|
|
511
|
-
policyAddress,
|
|
512
|
-
config.MACI.stateTreeDepth,
|
|
513
|
-
emptyBallotRoots,
|
|
514
|
-
], MACIFactory.abi, MACIFactory.linkBytecode({
|
|
515
|
-
"contracts/crypto/PoseidonT3.sol:PoseidonT3": "0x07490eba00dc4ACA6721D052Fa4C5002Aa077233",
|
|
516
|
-
"contracts/crypto/PoseidonT4.sol:PoseidonT4": "0xbb0e724CE02e5E7eDd31e632dc6e59F229a1126d",
|
|
517
|
-
"contracts/crypto/PoseidonT5.sol:PoseidonT5": "0xE0398F7DFAC494c530F6404AfEaC8669ABeD2679",
|
|
518
|
-
"contracts/crypto/PoseidonT6.sol:PoseidonT6": "0xfD77833F10a29c76A6a0ede235Eb651D744d0E2F",
|
|
519
|
-
}), kernelClient, bundlerClient, publicClient, chain);
|
|
520
|
-
// set the gate on the policy
|
|
521
|
-
await this.estimateGasAndSend(policyAddress, 0n, policyData.abi, "setTarget", [maciAddress], ErrorCodes.FAILED_TO_SET_MACI_INSTANCE_ON_POLICY.toString(), kernelClient, bundlerClient);
|
|
522
|
-
return { address: maciAddress };
|
|
374
|
+
const signer = await this.sessionKeysService.getCoordinatorSigner(chain, sessionKeyAddress, approval);
|
|
375
|
+
const policyContract = await this.deployAndSavePolicy(signer, chain, config.policy);
|
|
376
|
+
const policyAddress = await policyContract.getAddress();
|
|
377
|
+
const verifierContract = await deployVerifier(signer, true);
|
|
378
|
+
const verifyingKeysRegistryAddress = await deployVerifyingKeysRegistryContract({ signer });
|
|
379
|
+
const verifyingKeysArgs = await this.getVerifyingKeysArgs(signer, verifyingKeysRegistryAddress, config.VerifyingKeysRegistry.args, config.MACI.modes);
|
|
380
|
+
await setVerifyingKeys(verifyingKeysArgs);
|
|
381
|
+
// deploy the smart contracts
|
|
382
|
+
const maciAddresses = await deployMaci({
|
|
383
|
+
stateTreeDepth: config.MACI.stateTreeDepth,
|
|
384
|
+
signer,
|
|
385
|
+
signupPolicyAddress: policyAddress,
|
|
386
|
+
});
|
|
387
|
+
// store the contracts
|
|
388
|
+
await Promise.all([
|
|
389
|
+
this.storage.register({
|
|
390
|
+
id: EContracts.Verifier,
|
|
391
|
+
contract: verifierContract,
|
|
392
|
+
network: chain,
|
|
393
|
+
}),
|
|
394
|
+
this.storage.register({
|
|
395
|
+
id: EContracts.VerifyingKeysRegistry,
|
|
396
|
+
contract: new BaseContract(verifyingKeysRegistryAddress, VerifyingKeysRegistryFactory.abi),
|
|
397
|
+
network: chain,
|
|
398
|
+
}),
|
|
399
|
+
this.storage.register({
|
|
400
|
+
id: EContracts.MACI,
|
|
401
|
+
contract: new BaseContract(maciAddresses.maciContractAddress, MACIFactory.abi),
|
|
402
|
+
args: [
|
|
403
|
+
maciAddresses.pollFactoryContractAddress,
|
|
404
|
+
maciAddresses.messageProcessorFactoryContractAddress,
|
|
405
|
+
maciAddresses.tallyFactoryContractAddress,
|
|
406
|
+
policyAddress,
|
|
407
|
+
config.MACI.stateTreeDepth,
|
|
408
|
+
generateEmptyBallotRoots(config.MACI.stateTreeDepth).map((root) => root.toString()),
|
|
409
|
+
],
|
|
410
|
+
network: chain,
|
|
411
|
+
}),
|
|
412
|
+
]);
|
|
413
|
+
return { address: maciAddresses.maciContractAddress };
|
|
523
414
|
}
|
|
524
415
|
/**
|
|
525
416
|
* Deploy a poll
|
|
@@ -528,10 +419,7 @@ let DeployerService = DeployerService_1 = class DeployerService {
|
|
|
528
419
|
* @returns poll id
|
|
529
420
|
*/
|
|
530
421
|
async deployPoll({ approval, sessionKeyAddress, chain, config }) {
|
|
531
|
-
const
|
|
532
|
-
const bundlerClient = getBundlerClient(chain);
|
|
533
|
-
const kernelClient = await this.sessionKeysService.generateClientFromSessionKey(sessionKeyAddress, approval, chain);
|
|
534
|
-
const signer = await this.sessionKeysService.getKernelClientSigner(kernelClient);
|
|
422
|
+
const signer = await this.sessionKeysService.getCoordinatorSigner(chain, sessionKeyAddress, approval);
|
|
535
423
|
// check if there is a maci contract deployed on this chain
|
|
536
424
|
const maciAddress = this.storage.getAddress(EContracts.MACI, chain);
|
|
537
425
|
if (!maciAddress) {
|
|
@@ -547,91 +435,69 @@ let DeployerService = DeployerService_1 = class DeployerService {
|
|
|
547
435
|
if (!verifyingKeysRegistryAddress) {
|
|
548
436
|
throw new Error(ErrorCodes.VERIFYING_KEYS_REGISTRY_NOT_DEPLOYED.toString());
|
|
549
437
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
if (!policyAddress) {
|
|
553
|
-
const policyData = this.getPolicyData(config.policy.type, chain, config.policy.args);
|
|
554
|
-
policyAddress = policyData.address;
|
|
555
|
-
// if the policy is not already deployed, we need to deploy it
|
|
556
|
-
if (!policyData.alreadyDeployed) {
|
|
557
|
-
policyAddress = await this.deployAndStore(config.policy.type, config.policy.args ? Object.values(config.policy.args) : [], policyData.abi, policyData.bytecode, kernelClient, bundlerClient, publicClient, chain);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
438
|
+
const policyContract = await this.deployAndSavePolicy(signer, chain, config.policy);
|
|
439
|
+
const policyAddress = (await policyContract.getAddress());
|
|
560
440
|
// check if initial voice credit proxy address was given
|
|
561
441
|
let initialVoiceCreditProxyAddress = config.initialVoiceCreditsProxy.address;
|
|
562
442
|
if (!initialVoiceCreditProxyAddress) {
|
|
563
|
-
const
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
if (!voiceCreditProxyData.alreadyDeployed) {
|
|
567
|
-
initialVoiceCreditProxyAddress = await this.deployAndStore(config.initialVoiceCreditsProxy.type, Object.values(config.initialVoiceCreditsProxy.args), voiceCreditProxyData.abi, voiceCreditProxyData.bytecode, kernelClient, bundlerClient, publicClient, chain);
|
|
568
|
-
}
|
|
443
|
+
const initialVoiceCreditProxyFactory = await this.deployAndSaveVoiceCreditProxyFactory(signer, config.initialVoiceCreditsProxy.factoryType, chain);
|
|
444
|
+
const initialVoiceCreditProxyContract = await this.deployAndSaveVoiceCreditProxy(signer, config.initialVoiceCreditsProxy.type, chain, initialVoiceCreditProxyFactory, config.initialVoiceCreditsProxy.args);
|
|
445
|
+
initialVoiceCreditProxyAddress = await initialVoiceCreditProxyContract.getAddress();
|
|
569
446
|
}
|
|
570
|
-
|
|
447
|
+
// instantiate the coordinator MACI keypair
|
|
448
|
+
const coordinatorKeypair = getCoordinatorKeypair();
|
|
571
449
|
const deployPollArgs = {
|
|
572
450
|
maciAddress,
|
|
573
451
|
pollStartTimestamp: config.startDate,
|
|
574
452
|
pollEndTimestamp: config.endDate,
|
|
575
|
-
|
|
453
|
+
tallyProcessingStateTreeDepth: config.tallyProcessingStateTreeDepth,
|
|
576
454
|
voteOptionTreeDepth: config.voteOptionTreeDepth,
|
|
577
455
|
messageBatchSize: config.messageBatchSize,
|
|
578
456
|
stateTreeDepth: config.pollStateTreeDepth,
|
|
579
|
-
coordinatorPublicKey:
|
|
457
|
+
coordinatorPublicKey: coordinatorKeypair.publicKey,
|
|
580
458
|
verifierContractAddress: verifierAddress,
|
|
581
459
|
verifyingKeysRegistryContractAddress: verifyingKeysRegistryAddress,
|
|
582
|
-
mode,
|
|
460
|
+
mode: config.mode,
|
|
583
461
|
policyContractAddress: policyAddress,
|
|
584
462
|
initialVoiceCreditProxyContractAddress: initialVoiceCreditProxyAddress,
|
|
585
|
-
relayers: config.relayers ? config.relayers
|
|
463
|
+
relayers: config.relayers ? config.relayers : [],
|
|
586
464
|
voteOptions: Number(config.voteOptions),
|
|
587
465
|
initialVoiceCredits: Number(config.initialVoiceCreditsProxy.args.amount),
|
|
588
466
|
signer,
|
|
589
467
|
};
|
|
590
468
|
const { pollContractAddress, messageProcessorContractAddress, tallyContractAddress, pollId } = await deployPoll(deployPollArgs);
|
|
591
469
|
const poll = PollFactory.connect(pollContractAddress, signer);
|
|
592
|
-
// read the emptyBallotRoot and extContracts
|
|
593
|
-
const emptyBallotRoot = await poll.emptyBallotRoot();
|
|
594
|
-
const extContracts = await poll.extContracts();
|
|
595
470
|
// store to storage
|
|
596
471
|
await Promise.all([
|
|
597
472
|
this.storage.register({
|
|
598
473
|
id: EContracts.Poll,
|
|
599
474
|
key: `poll-${pollId}`,
|
|
600
475
|
contract: poll,
|
|
601
|
-
args
|
|
602
|
-
|
|
603
|
-
...deployPollArgs,
|
|
604
|
-
extContracts,
|
|
605
|
-
emptyBallotRoot: emptyBallotRoot.toString(),
|
|
606
|
-
},
|
|
607
|
-
],
|
|
476
|
+
// clones do not have args for verification
|
|
477
|
+
args: [],
|
|
608
478
|
network: chain,
|
|
609
479
|
}),
|
|
610
480
|
this.storage.register({
|
|
611
481
|
id: EContracts.MessageProcessor,
|
|
612
482
|
key: `poll-${pollId}`,
|
|
613
|
-
contract:
|
|
614
|
-
|
|
483
|
+
contract: MessageProcessorFactory.connect(messageProcessorContractAddress, signer),
|
|
484
|
+
// clones do not have args for verification
|
|
485
|
+
args: [],
|
|
615
486
|
network: chain,
|
|
616
487
|
}),
|
|
617
488
|
this.storage.register({
|
|
618
489
|
id: EContracts.Tally,
|
|
619
490
|
key: `poll-${pollId}`,
|
|
620
|
-
contract:
|
|
621
|
-
args
|
|
622
|
-
|
|
623
|
-
verifyingKeysRegistryAddress,
|
|
624
|
-
pollContractAddress,
|
|
625
|
-
messageProcessorContractAddress,
|
|
626
|
-
mode,
|
|
627
|
-
],
|
|
491
|
+
contract: TallyFactory.connect(tallyContractAddress, signer),
|
|
492
|
+
// clones do not have args for verification
|
|
493
|
+
args: [],
|
|
628
494
|
network: chain,
|
|
629
495
|
}),
|
|
630
496
|
]);
|
|
631
497
|
return { pollId: pollId.toString() };
|
|
632
498
|
}
|
|
633
499
|
};
|
|
634
|
-
DeployerService =
|
|
500
|
+
DeployerService = __decorate([
|
|
635
501
|
Injectable(),
|
|
636
502
|
__metadata("design:paramtypes", [SessionKeysService,
|
|
637
503
|
FileService])
|