Skip to content

Commit cfcbbde

Browse files
ShahakShamaclaude
andcommitted
apollo_l1_gas_price_types,apollo_l1_gas_price: expose get_strk_to_usd_rate
Goal: PR 3 of 6 in the stack moving the STRK/USD oracle into L1GasPriceProvider. Surfaces the inherent method added in PR 2 on the client trait so cross-process callers (notably the consensus orchestrator in PR 5) can request a STRK/USD rate without holding their own oracle. Change summary: - New `L1GasPriceRequest::GetStrkToUsdRate(u64)` variant. - New `L1GasPriceResponse::GetStrkToUsdRate(L1GasPriceProviderResult<u128>)` variant. - New `L1GasPriceProviderClient::get_strk_to_usd_rate` trait method, implemented on the blanket impl mirroring `get_rate`. - Server-side dispatch arm in `apollo_l1_gas_price::communication` routes to `L1GasPriceProvider::strk_to_usd_rate`. Decision points: - Did not rename the existing `get_rate` (which dispatches to `GetEthToFriRate`) for symmetry; out of scope per the stack plan and would churn unrelated call sites in consensus orchestrator. The trait now has slightly asymmetric naming: `get_rate` (ETH/FRI) vs `get_strk_to_usd_rate`. Renaming is a separate cleanup if desired. - `MockL1GasPriceProviderClient` is automock-generated and picks up the new method automatically. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c997caa commit cfcbbde

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

crates/apollo_l1_gas_price/src/communication.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ impl ComponentRequestHandler<L1GasPriceRequest, L1GasPriceResponse> for L1GasPri
3232
L1GasPriceRequest::GetEthToFriRate(timestamp) => {
3333
L1GasPriceResponse::GetEthToFriRate(self.eth_to_fri_rate(timestamp).await)
3434
}
35+
L1GasPriceRequest::GetStrkToUsdRate(timestamp) => {
36+
L1GasPriceResponse::GetStrkToUsdRate(self.strk_to_usd_rate(timestamp).await)
37+
}
3538
}
3639
}
3740
}

crates/apollo_l1_gas_price_types/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub enum L1GasPriceRequest {
7171
GetGasPrice(BlockTimestamp),
7272
AddGasPrice(GasPriceData),
7373
GetEthToFriRate(u64),
74+
GetStrkToUsdRate(u64),
7475
}
7576
impl_debug_for_infra_requests_and_responses!(L1GasPriceRequest);
7677
impl_labeled_request!(L1GasPriceRequest, L1GasPriceRequestLabelValue);
@@ -82,6 +83,7 @@ pub enum L1GasPriceResponse {
8283
GetGasPrice(L1GasPriceProviderResult<PriceInfo>),
8384
AddGasPrice(L1GasPriceProviderResult<()>),
8485
GetEthToFriRate(L1GasPriceProviderResult<u128>),
86+
GetStrkToUsdRate(L1GasPriceProviderResult<u128>),
8587
}
8688
impl_debug_for_infra_requests_and_responses!(L1GasPriceResponse);
8789

@@ -100,6 +102,8 @@ pub trait L1GasPriceProviderClient: Send + Sync {
100102
) -> L1GasPriceProviderClientResult<PriceInfo>;
101103

102104
async fn get_rate(&self, timestamp: u64) -> L1GasPriceProviderClientResult<u128>;
105+
106+
async fn get_strk_to_usd_rate(&self, timestamp: u64) -> L1GasPriceProviderClientResult<u128>;
103107
}
104108

105109
#[cfg_attr(any(feature = "testing", test), automock)]
@@ -171,6 +175,19 @@ where
171175
Direct
172176
)
173177
}
178+
#[instrument(skip(self))]
179+
async fn get_strk_to_usd_rate(&self, timestamp: u64) -> L1GasPriceProviderClientResult<u128> {
180+
let request = L1GasPriceRequest::GetStrkToUsdRate(timestamp);
181+
handle_all_response_variants!(
182+
self,
183+
request,
184+
L1GasPriceResponse,
185+
GetStrkToUsdRate,
186+
L1GasPriceClientError,
187+
L1GasPriceProviderError,
188+
Direct
189+
)
190+
}
174191
}
175192

176193
generate_permutation_labels! {

0 commit comments

Comments
 (0)