1
1
import { type KeyLike } from "crypto" ;
2
+ import { Poll__factory as PollFactory } from "@maci-protocol/contracts" ;
2
3
import { EMode } from "@maci-protocol/core" ;
3
4
import { getPoll } from "@maci-protocol/sdk/browser" ;
4
- import { PUBLIC_CHAIN , PUBLIC_COORDINATOR_SERVICE_URL , PUBLIC_MACI_ADDRESS , PUBLIC_WEB3_ENDPOINT } from "@/constants" ;
5
+ import {
6
+ PUBLIC_CHAIN ,
7
+ PUBLIC_COORDINATOR_SERVICE_URL ,
8
+ PUBLIC_MACI_ADDRESS ,
9
+ PUBLIC_MACI_DEPLOYMENT_BLOCK ,
10
+ PUBLIC_WEB3_ENDPOINT ,
11
+ } from "@/constants" ;
5
12
import { createContext , type ReactNode , useCallback , useMemo , useState } from "react" ;
6
13
import { createPublicClient , hashMessage , http , parseAbi , toBytes } from "viem" ;
7
14
import { useSignMessage } from "wagmi" ;
@@ -16,6 +23,7 @@ import {
16
23
import { encryptWithCoordinatorRSA } from "./auth" ;
17
24
import { GenerateResponseSchema , SubmitResponseSchema } from "./schemas" ;
18
25
import { useEthersSigner } from "../hooks/useEthersSigner" ;
26
+ import { getFutureBlockNumberAtTimestamp } from "../utils/blockAtTimestamp" ;
19
27
20
28
const baseUrl = PUBLIC_COORDINATOR_SERVICE_URL ;
21
29
const maciContractAddress = PUBLIC_MACI_ADDRESS ;
@@ -185,13 +193,8 @@ export const CoordinatorProvider = ({ children }: { children: ReactNode }) => {
185
193
pollId,
186
194
signer,
187
195
} ) ;
188
- const pollAbi = parseAbi ( [ "function stateMerged() view returns (bool)" ] ) ;
189
- const statemMerged = await publicClient . readContract ( {
190
- address : pollAddress as `0x${string } `,
191
- abi : pollAbi ,
192
- functionName : "stateMerged" ,
193
- } ) ;
194
- return statemMerged ;
196
+ const poll = PollFactory . connect ( pollAddress , signer ) ;
197
+ return await poll . stateMerged ( ) ;
195
198
} ;
196
199
197
200
const finalizeProposal = useCallback ( async ( pollId : number ) => {
@@ -205,10 +208,16 @@ export const CoordinatorProvider = ({ children }: { children: ReactNode }) => {
205
208
}
206
209
setFinalizeStatus ( "merged" ) ;
207
210
208
- // TODO: get these values
211
+ const { address : pollAddress } = await getPoll ( {
212
+ maciAddress : PUBLIC_MACI_ADDRESS ,
213
+ pollId,
214
+ signer,
215
+ } ) ;
216
+ const poll = PollFactory . connect ( pollAddress , signer ) ;
217
+ const endDate = await poll . endDate ( ) ;
209
218
const encryptedCoordinatorPrivateKey = "" ;
210
- const startBlock = 0 ;
211
- const endBlock = 0 ;
219
+ const startBlock = PUBLIC_MACI_DEPLOYMENT_BLOCK ;
220
+ const endBlock = Number ( await getFutureBlockNumberAtTimestamp ( endDate ) ) ;
212
221
213
222
setFinalizeStatus ( "proving" ) ;
214
223
const proveResult = await generateProofs ( {
0 commit comments