Skip to content

Commit f988b4e

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 dc3f241 commit f988b4e

2 files changed

Lines changed: 22 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: 19 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

@@ -99,7 +101,11 @@ pub trait L1GasPriceProviderClient: Send + Sync {
99101
timestamp: BlockTimestamp,
100102
) -> L1GasPriceProviderClientResult<PriceInfo>;
101103

104+
/// ETH/FRI rate as 18-decimal fixed-point integer (e.g. 5000 STRK per ETH → `5000 * 10^18`).
102105
async fn get_rate(&self, timestamp: u64) -> L1GasPriceProviderClientResult<u128>;
106+
107+
/// STRK/USD rate as 18-decimal fixed-point integer (e.g. 24.5 STRK per USD → `24.5 * 10^18`).
108+
async fn get_strk_to_usd_rate(&self, timestamp: u64) -> L1GasPriceProviderClientResult<u128>;
103109
}
104110

105111
#[cfg_attr(any(feature = "testing", test), automock)]
@@ -171,6 +177,19 @@ where
171177
Direct
172178
)
173179
}
180+
#[instrument(skip(self))]
181+
async fn get_strk_to_usd_rate(&self, timestamp: u64) -> L1GasPriceProviderClientResult<u128> {
182+
let request = L1GasPriceRequest::GetStrkToUsdRate(timestamp);
183+
handle_all_response_variants!(
184+
self,
185+
request,
186+
L1GasPriceResponse,
187+
GetStrkToUsdRate,
188+
L1GasPriceClientError,
189+
L1GasPriceProviderError,
190+
Direct
191+
)
192+
}
174193
}
175194

176195
generate_permutation_labels! {

0 commit comments

Comments
 (0)