@maci-protocol/coordinator 0.0.0-ci.e3476db → 0.0.0-ci.e52a091

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