chia_sdk_driver/offers/
offer_amounts.rs1use std::ops::Add;
2
3use chia_protocol::Bytes32;
4use indexmap::IndexMap;
5
6#[derive(Debug, Default, Clone)]
7pub struct Arbitrage {
8 pub offered: ArbitrageSide,
9 pub requested: ArbitrageSide,
10}
11
12impl Arbitrage {
13 pub fn new() -> Self {
14 Self::default()
15 }
16}
17
18#[derive(Debug, Default, Clone)]
19pub struct ArbitrageSide {
20 pub xch: u64,
21 pub cats: IndexMap<Bytes32, u64>,
22 pub nfts: Vec<Bytes32>,
23 pub options: Vec<Bytes32>,
24}
25
26impl ArbitrageSide {
27 pub fn new() -> Self {
28 Self::default()
29 }
30
31 pub fn amounts(&self) -> OfferAmounts {
32 OfferAmounts {
33 xch: self.xch,
34 cats: self.cats.clone(),
35 }
36 }
37}
38
39#[derive(Debug, Default, Clone)]
40pub struct OfferAmounts {
41 pub xch: u64,
42 pub cats: IndexMap<Bytes32, u64>,
43}
44
45impl OfferAmounts {
46 pub fn new() -> Self {
47 Self::default()
48 }
49}
50
51impl Add for &OfferAmounts {
52 type Output = OfferAmounts;
53
54 fn add(self, other: Self) -> Self::Output {
55 let mut cats = self.cats.clone();
56
57 for (&asset_id, amount) in &other.cats {
58 *cats.entry(asset_id).or_insert(0) += amount;
59 }
60
61 Self::Output {
62 xch: self.xch + other.xch,
63 cats,
64 }
65 }
66}