chia_sdk_driver/offers/
offer_amounts.rs

1use std::ops::Add;
2
3use chia_protocol::Bytes32;
4use indexmap::IndexMap;
5
6#[derive(Debug, Default, Clone)]
7pub struct Arbitrage {
8    pub offered: OfferAmounts,
9    pub requested: OfferAmounts,
10    pub offered_nfts: Vec<Bytes32>,
11    pub requested_nfts: Vec<Bytes32>,
12}
13
14impl Arbitrage {
15    pub fn new() -> Self {
16        Self::default()
17    }
18}
19
20#[derive(Debug, Default, Clone)]
21pub struct OfferAmounts {
22    pub xch: u64,
23    pub cats: IndexMap<Bytes32, u64>,
24}
25
26impl OfferAmounts {
27    pub fn new() -> Self {
28        Self::default()
29    }
30}
31
32impl Add for &OfferAmounts {
33    type Output = OfferAmounts;
34
35    fn add(self, other: Self) -> Self::Output {
36        let mut cats = self.cats.clone();
37
38        for (&asset_id, amount) in &other.cats {
39            *cats.entry(asset_id).or_insert(0) += amount;
40        }
41
42        Self::Output {
43            xch: self.xch + other.xch,
44            cats,
45        }
46    }
47}