After you file

The custodian according to IRS is supposed to calculate the earnings

 

 

worksheet

https://www.connexuscu.org/wp-content/uploads/2022/06/HSA-Earnings-Calculation-Worksheet.pdf 

 

 

also from CFR 1.408-11

while this refers to IRAs the same rules apply to an HSA

https://www.law.cornell.edu/cfr/text/26/1.408-11 

 

if you have multiple investment accounts for the HSA it's the total value of the accounts on the same date.