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