1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// SPDX-FileCopyrightText: 2025 Semiotic AI, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//! Error types for price calculations.
//!
//! This module provides error types for operations in the `price` module,
//! particularly for calculating token prices from swap events.
use Address;
use RpcError;
/// Errors that can occur during price calculations.
///
/// This error type wraps [`crate::price::PriceSourceError`] (which handles
/// event decoding and validation) and adds additional error cases for
/// metadata fetching, processing failures, and RPC errors.
///
/// # Examples
///
/// ```rust,ignore
/// use semioscan::{PriceCalculator, PriceCalculationError};
/// use alloy_chains::NamedChain;
///
/// async fn example() -> Result<(), PriceCalculationError> {
/// let calculator = PriceCalculator::new(provider, NamedChain::Arbitrum, usdc_address, price_source);
///
/// match calculator.calculate_price_between_blocks(token_address, start_block, end_block).await {
/// Ok(result) => println!("Price data: {:?}", result),
/// Err(PriceCalculationError::MetadataFetchFailed { token, .. }) => {
/// eprintln!("Failed to fetch metadata for token {}", token);
/// }
/// Err(PriceCalculationError::Rpc(e)) => {
/// eprintln!("RPC error, will retry: {}", e);
/// }
/// Err(e) => eprintln!("Other error: {}", e),
/// }
/// Ok(())
/// }
/// ```