@@ -133,45 +133,7 @@ const accumulateDepositsRequest = (
133133 for ( let i = 0 ; i < tx . receipt . logs . length ; i ++ ) {
134134 const log = tx . receipt . logs [ i ]
135135 if ( bytesToHex ( log [ 0 ] ) . toLowerCase ( ) === depositContractAddressLowerCase ) {
136- // Extracts validator pubkey, withdrawal credential, deposit amount, signature,
137- // and validator index from Deposit Event log.
138- // The event fields are non-indexed so contained in one byte array (log[2]) so parsing is as follows:
139- // 1. Read the first 32 bytes to get the starting position of the first field.
140- // 2. Continue reading the byte array in 32 byte increments to get all the field starting positions
141- // 3. Read 32 bytes starting with the first field position to get the size of the first field
142- // 4. Read the bytes from first field position + 32 + the size of the first field to get the first field value
143- // 5. Repeat steps 3-4 for each field
144- // This is equivalent to ABI-decoding the event:
145- // event DepositEvent(
146- // bytes pubkey,
147- // bytes withdrawal_credentials,
148- // bytes amount,
149- // bytes signature,
150- // bytes index
151- //);
152-
153- const pubKeyIdx = bytesToInt ( log [ 2 ] . slice ( 0 , 32 ) )
154- const pubKeySize = bytesToInt ( log [ 2 ] . slice ( pubKeyIdx , pubKeyIdx + 32 ) )
155- const withdrawalCreditsIdx = bytesToInt ( log [ 2 ] . slice ( 32 , 64 ) )
156- const withdrawalCreditsSize = bytesToInt (
157- log [ 2 ] . slice ( withdrawalCreditsIdx , withdrawalCreditsIdx + 32 ) ,
158- )
159- const amountIdx = bytesToInt ( log [ 2 ] . slice ( 64 , 96 ) )
160- const amountSize = bytesToInt ( log [ 2 ] . slice ( amountIdx , amountIdx + 32 ) )
161- const sigIdx = bytesToInt ( log [ 2 ] . slice ( 96 , 128 ) )
162- const sigSize = bytesToInt ( log [ 2 ] . slice ( sigIdx , sigIdx + 32 ) )
163- const indexIdx = bytesToInt ( log [ 2 ] . slice ( 128 , 160 ) )
164- const indexSize = bytesToInt ( log [ 2 ] . slice ( indexIdx , indexIdx + 32 ) )
165-
166- const pubkey = log [ 2 ] . slice ( pubKeyIdx + 32 , pubKeyIdx + 32 + pubKeySize )
167- const withdrawalCredentials = log [ 2 ] . slice (
168- withdrawalCreditsIdx + 32 ,
169- withdrawalCreditsIdx + 32 + withdrawalCreditsSize ,
170- )
171- const amount = log [ 2 ] . slice ( amountIdx + 32 , amountIdx + 32 + amountSize )
172- const signature = log [ 2 ] . slice ( sigIdx + 32 , sigIdx + 32 + sigSize )
173- const index = log [ 2 ] . slice ( indexIdx + 32 , indexIdx + 32 + indexSize )
174-
136+ const { pubkey, withdrawalCredentials, amount, signature, index } = parseDepositLog ( log [ 2 ] )
175137 const depositRequestBytes = concatBytes (
176138 pubkey ,
177139 withdrawalCredentials ,
@@ -187,3 +149,43 @@ const accumulateDepositsRequest = (
187149
188150 return new DepositRequest ( resultsBytes )
189151}
152+
153+ function parseDepositLog ( requestData : Uint8Array ) {
154+ // Extracts validator pubkey, withdrawal credential, deposit amount, signature,
155+ // and validator index from Deposit Event log.
156+ // The event fields are non-indexed so contained in one byte array (log[2]) so parsing is as follows:
157+ // 1. Read the first 32 bytes to get the starting position of the first field.
158+ // 2. Continue reading the byte array in 32 byte increments to get all the field starting positions
159+ // 3. Read 32 bytes starting with the first field position to get the size of the first field
160+ // 4. Read the bytes from first field position + 32 + the size of the first field to get the first field value
161+ // 5. Repeat steps 3-4 for each field
162+ const pubKeyIdx = bytesToInt ( requestData . slice ( 0 , 32 ) )
163+ const pubKeySize = bytesToInt ( requestData . slice ( pubKeyIdx , pubKeyIdx + 32 ) )
164+ const withdrawalCreditsIdx = bytesToInt ( requestData . slice ( 32 , 64 ) )
165+ const withdrawalCreditsSize = bytesToInt (
166+ requestData . slice ( withdrawalCreditsIdx , withdrawalCreditsIdx + 32 ) ,
167+ )
168+ const amountIdx = bytesToInt ( requestData . slice ( 64 , 96 ) )
169+ const amountSize = bytesToInt ( requestData . slice ( amountIdx , amountIdx + 32 ) )
170+ const sigIdx = bytesToInt ( requestData . slice ( 96 , 128 ) )
171+ const sigSize = bytesToInt ( requestData . slice ( sigIdx , sigIdx + 32 ) )
172+ const indexIdx = bytesToInt ( requestData . slice ( 128 , 160 ) )
173+ const indexSize = bytesToInt ( requestData . slice ( indexIdx , indexIdx + 32 ) )
174+
175+ const pubkey = requestData . slice ( pubKeyIdx + 32 , pubKeyIdx + 32 + pubKeySize )
176+ const withdrawalCredentials = requestData . slice (
177+ withdrawalCreditsIdx + 32 ,
178+ withdrawalCreditsIdx + 32 + withdrawalCreditsSize ,
179+ )
180+ const amount = requestData . slice ( amountIdx + 32 , amountIdx + 32 + amountSize )
181+ const signature = requestData . slice ( sigIdx + 32 , sigIdx + 32 + sigSize )
182+ const index = requestData . slice ( indexIdx + 32 , indexIdx + 32 + indexSize )
183+
184+ return {
185+ pubkey,
186+ withdrawalCredentials,
187+ amount,
188+ signature,
189+ index,
190+ }
191+ }
0 commit comments