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
use console::style;
use std::fmt::{Debug, Display};
use vyper_core::state::{
    SlotTracking
};
use rust_decimal::{
    Decimal,
};

use anchor_client::solana_sdk::{
        pubkey:: Pubkey
};

use std::process::exit;
use solana_cli_config::{CONFIG_FILE, Config};



pub fn println_name_value<T:Debug>(name: &str, value: &T) {
    println!(
        "{} : {:?} ",
        style(name).bold(),
        style(value),
    );
}

pub fn println_version<T:Display>(name: &str, value: &[T]) {
    println!(
        "{} : {}.{}.{}",
        style(name).bold(),
        style(&value[0]),
        style(&value[1]),
        style(&value[2])
    );
}

pub fn println_name_fair_value(name: &str, fair_value: &[[u8;16]], slot: &SlotTracking) {
    print!(
        "{} : {{ value: [",
        style(name).bold(),
    );
    println_fair_value(&fair_value);
    print!("], slot_tracking: ",);
    println!("{:?} }}",slot);
}

pub fn println_error(err: &str) {
    println!(
        "{} : {}",
        style("error").red().bold(),
        style(err)
    );
}

pub fn get_solana_config() -> Config {
    let config_file = CONFIG_FILE.as_ref();
    let config_file = match config_file {
        Some(file) => file,
        None => {
            println_error("Could not read the config file");
            exit(1);
        }
    };
    let cli_config = Config::load(config_file);
    match cli_config {
        Ok(config) => config,
        Err(_) => {
            println_error("Could not load the config file");
            exit(1);
        }
    }
}

pub fn println_fair_value(fair_value: &[[u8; 16]]) {
    let mut first: bool = true;
    for value in fair_value {
        if !first {
            print!(",");
        }
        print!(
            "{}",
            style(&Decimal::deserialize(*value)),
        );
        first=false;
    }
}

pub fn println_switchboard_aggregators(name: &str, aggregators: &[Option<Pubkey>; 10]) {
    print!(
        "{} : [",
        style(name).bold(),
    );
    let mut first: bool = true;
    for value in aggregators {
        match value {
            Some(key) => {
                if !first {
                    print!(",{}",key)
                }
                else {
                    print!("{}",key);
                }
            }
            None => break
        }
        first=false;
    }
    println!("]")
}