@@ -102,25 +102,19 @@ func (s *currencyServer) GetHistoricalMintData(ctx context.Context, req *currenc
102102 }, nil
103103 }
104104
105- // Get exchange rate history (cached by currency code + range)
106- exchangeRateHistory , err := s .getCachedExchangeRateHistory (
107- ctx ,
108- currencyCode ,
109- req .GetPredefinedRange (),
110- startTime ,
111- endTime ,
112- interval ,
113- )
114- if err == currency .ErrNotFound {
105+ // Always use the latest FX rate for the entire data set
106+ liveExchangeRates , err := s .mintDataProvider .GetLiveExchangeRates (ctx )
107+ if err != nil {
108+ log .With (zap .Error (err )).Warn ("failed to load live exchange rates" )
109+ return nil , status .Error (codes .Internal , "" )
110+ }
111+ if liveExchangeRates == nil {
115112 return & currencypb.GetHistoricalMintDataResponse {
116113 Result : currencypb .GetHistoricalMintDataResponse_MISSING_DATA ,
117114 }, nil
118- } else if err != nil {
119- log .With (zap .Error (err )).Warn ("failed to load exchange rate history" )
120- return nil , status .Error (codes .Internal , "" )
121115 }
122-
123- if len ( exchangeRateHistory ) == 0 {
116+ latestExchangeRate , ok := liveExchangeRates . Rates [ string ( currencyCode )]
117+ if ! ok {
124118 return & currencypb.GetHistoricalMintDataResponse {
125119 Result : currencypb .GetHistoricalMintDataResponse_MISSING_DATA ,
126120 }, nil
@@ -151,15 +145,9 @@ func (s *currencyServer) GetHistoricalMintData(ctx context.Context, req *currenc
151145 }
152146
153147 for _ , reserve := range reserveHistory {
154- // Find the closest exchange rate for this time point
155- exchangeRate , ok := findClosestExchangeRate (reserve .Time , exchangeRateHistory )
156- if ! ok {
157- continue
158- }
159-
160148 data = append (data , & currencypb.HistoricalMintData {
161149 Timestamp : timestamppb .New (reserve .Time ),
162- MarketCap : currency_util .CalculateMarketCap (reserve .SupplyFromBonding , exchangeRate ),
150+ MarketCap : currency_util .CalculateMarketCap (reserve .SupplyFromBonding , latestExchangeRate ),
163151 })
164152 }
165153
@@ -174,15 +162,9 @@ func (s *currencyServer) GetHistoricalMintData(ctx context.Context, req *currenc
174162 return
175163 }
176164
177- latestExchangeRate , err := s .data .GetExchangeRate (ctx , currencyCode , latestTime )
178- if err != nil {
179- log .With (zap .Error (err )).Warn ("failed to load latest exchange rate" )
180- return
181- }
182-
183165 data = append (data , & currencypb.HistoricalMintData {
184166 Timestamp : timestamppb .New (latestTime ),
185- MarketCap : currency_util .CalculateMarketCap (latestReserve .SupplyFromBonding , latestExchangeRate . Rate ),
167+ MarketCap : currency_util .CalculateMarketCap (latestReserve .SupplyFromBonding , latestExchangeRate ),
186168 })
187169 }()
188170 }
0 commit comments