loom_types_blockchain/
swap.rs

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
use alloy_primitives::{Address, U256};
use eyre::{eyre, Report};
use std::hash::{Hash, Hasher};

#[derive(Clone, Debug)]
pub struct SwapError {
    pub msg: String,
    pub pool: Address,
    pub token_from: Address,
    pub token_to: Address,
    pub is_in_amount: bool,
    pub amount: U256,
}

impl From<SwapError> for Report {
    fn from(value: SwapError) -> Self {
        eyre!(value.msg)
    }
}

impl Hash for SwapError {
    fn hash<H: Hasher>(&self, state: &mut H) {
        self.pool.hash(state);
        self.token_from.hash(state);
        self.token_to.hash(state);
    }
}

impl PartialEq<Self> for SwapError {
    fn eq(&self, other: &Self) -> bool {
        self.pool == other.pool && self.token_to == other.token_to && self.token_from == other.token_from
    }
}

impl Eq for SwapError {}