@@ -53,6 +53,39 @@ import { createViemClient } from './createClient';
5353
5454const initDirName = `ui/${ coreName } ` ;
5555
56+ export const PROPOSAL_ID_THRESHOLD = 272 ;
57+
58+ const VOTING_MACHINE_ADDRESSES : Record <
59+ number ,
60+ { oldAddress : Address ; newAddress : Address }
61+ > = {
62+ 1 : {
63+ oldAddress : '0x617332a777780F546261247F621051d0b98975Eb' as Address ,
64+ newAddress : '0x06a1795a88b82700896583e123F46BE43877bFb6' as Address ,
65+ } ,
66+ 137 : {
67+ oldAddress : '0xc8a2ADC4261c6b669CdFf69E717E77C9cFeB420d' as Address ,
68+ newAddress : '0x44c8b753229006A8047A05b90379A7e92185E97C' as Address ,
69+ } ,
70+ 43114 : {
71+ oldAddress : '0x9b6f5ef589A3DD08670Dd146C11C4Fb33E04494F' as Address ,
72+ newAddress : '0x4D1863d22D0ED8579f8999388BCC833CB057C2d6' as Address ,
73+ } ,
74+ } ;
75+
76+ export function getVotingMachineAddress (
77+ chainId : number ,
78+ proposalId : number ,
79+ ) : Address {
80+ const addresses = VOTING_MACHINE_ADDRESSES [ chainId ] ;
81+ if ( ! addresses ) {
82+ throw new Error ( `No voting machine addresses found for chain ${ chainId } ` ) ;
83+ }
84+ return proposalId > PROPOSAL_ID_THRESHOLD
85+ ? addresses . newAddress
86+ : addresses . oldAddress ;
87+ }
88+
5689async function getVotingData ( initialProposals : InitialProposal [ ] ) {
5790 const votingMachineDataHelpers = {
5891 [ appConfig . votingMachineChainIds [ 0 ] ] : getContract ( {
@@ -87,30 +120,50 @@ async function getVotingData(initialProposals: InitialProposal[]) {
87120 . map ( ( data ) => data . votingChainId )
88121 . filter ( ( value , index , self ) => self . indexOf ( value ) === index ) ;
89122
90- const votingMachines : Record < number , Hex > = { } ;
91123 const data = await Promise . all (
92124 votingMachineChainIds . map ( async ( chainId ) => {
93125 const votingMachineDataHelper = votingMachineDataHelpers [ chainId ] ;
94126
95- const formattedInitialProposals = initialProposals
96- . filter ( ( proposal ) => proposal . votingChainId === chainId )
97- . map ( ( proposal ) => {
98- return {
99- id : proposal . id ,
100- snapshotBlockHash : proposal . snapshotBlockHash ,
101- } ;
102- } ) ;
103-
104- votingMachines [ chainId ] =
105- appConfig . votingMachineConfig [ chainId ] . contractAddress ;
106-
107- return (
108- ( await votingMachineDataHelper . read . getProposalsData ( [
109- appConfig . votingMachineConfig [ chainId ] . contractAddress ,
110- formattedInitialProposals ,
127+ const { oldFormattedInitialProposals, newFormattedInitialProposals } =
128+ initialProposals
129+ . filter ( ( proposal ) => proposal . votingChainId === chainId )
130+ . map ( ( { id, snapshotBlockHash } ) => ( { id, snapshotBlockHash } ) )
131+ . reduce (
132+ ( acc , proposal ) => {
133+ if ( proposal . id <= PROPOSAL_ID_THRESHOLD ) {
134+ acc . oldFormattedInitialProposals . push ( proposal ) ;
135+ } else {
136+ acc . newFormattedInitialProposals . push ( proposal ) ;
137+ }
138+ return acc ;
139+ } ,
140+ {
141+ oldFormattedInitialProposals : [ ] as {
142+ id : bigint ;
143+ snapshotBlockHash : `0x${string } `;
144+ } [ ] ,
145+ newFormattedInitialProposals : [ ] as {
146+ id : bigint ;
147+ snapshotBlockHash : `0x${string } `;
148+ } [ ] ,
149+ } ,
150+ ) ;
151+
152+ const firstNewProposalId = newFormattedInitialProposals [ 0 ] . id ;
153+ const [ oldProposalsData , newProposalsData ] = await Promise . all ( [
154+ votingMachineDataHelper . read . getProposalsData ( [
155+ getVotingMachineAddress ( chainId , 0 ) ,
156+ oldFormattedInitialProposals ,
111157 zeroAddress ,
112- ] ) ) || [ ]
113- ) ;
158+ ] ) ,
159+ votingMachineDataHelper . read . getProposalsData ( [
160+ getVotingMachineAddress ( chainId , Number ( firstNewProposalId ) ) ,
161+ newFormattedInitialProposals ,
162+ zeroAddress ,
163+ ] ) ,
164+ ] ) ;
165+
166+ return [ ...oldProposalsData , ...newProposalsData ] ;
114167 } ) ,
115168 ) ;
116169
@@ -631,10 +684,14 @@ async function parseCache() {
631684 const proposalIpfsData = ipfsCache [ proposal . ipfsHash ] ;
632685
633686 const path = `${ proposal . votingChainId } /events` ;
687+ const votingMachineAddress = getVotingMachineAddress (
688+ proposal . votingChainId ,
689+ proposal . id ,
690+ ) ;
634691 const votesCache =
635692 readJSONCache < Awaited < ReturnType < typeof getVotingMachineEvents > > > (
636693 path ,
637- appConfig . votingMachineConfig [ proposal . votingChainId ] . contractAddress ,
694+ votingMachineAddress ,
638695 ) || [ ] ;
639696
640697 // format VoteEmitted events to UI data format
0 commit comments