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
use crate::SELF;
use eosio::{
    n, s, Asset, NumBytes, PrimaryTableIndex, Read, Symbol, Table, TableName,
    Write,
};
use lazy_static::lazy_static;

#[derive(Read, Write, NumBytes, Default)]
pub struct ExchangeState {
    pub supply: Asset,
    pub base: Connector,
    pub quote: Connector,
}

#[derive(Read, Write, NumBytes)]
pub struct Connector {
    pub balance: Asset,
    pub weight: f64,
}

impl Default for Connector {
    fn default() -> Self {
        Self {
            balance: Asset::default(),
            weight: 0.5,
        }
    }
}

pub struct RamMarket;

impl Table for RamMarket {
    type Row = ExchangeState;

    const NAME: TableName = TableName::new(n!("rammarket"));

    fn primary_key(row: &Self::Row) -> u64 {
        row.supply.symbol.as_u64()
    }
}

pub const RAMCORE_SYMBOL: Symbol = Symbol::new(s!(4, "RAMCORE"));
pub const RAM_SYMBOL: Symbol = Symbol::new(s!(0, "RAM"));

lazy_static! {
    pub static ref RAMMARKET: PrimaryTableIndex<RamMarket> =
        RamMarket::table(*SELF, *SELF);
}