tensor_eigen/formatting/
price_lock.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
use console::Style;
use tensor_price_lock::accounts::{OrderNftReceipt, OrderState};

use crate::formatting::{format_timestamp, option_formatter, pad_label};

use super::CustomFormat;

const LABEL_LENGTH: usize = 25;

impl CustomFormat for OrderState {
    fn custom_format(&self) -> String {
        // Use the default text color but set this up for future use.
        let color = Style::new();

        format!(
            "{}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}
{}: {}",
            color.apply_to("OrderState---------------"),
            pad_label("discriminator", LABEL_LENGTH),
            color.apply_to(hex::encode(self.discriminator)),
            pad_label("version", LABEL_LENGTH),
            color.apply_to(self.version),
            pad_label("bump", LABEL_LENGTH),
            color.apply_to(self.bump[0]),
            pad_label("order_id", LABEL_LENGTH),
            color.apply_to(hex::encode(self.order_id)),
            pad_label("order_type", LABEL_LENGTH),
            color.apply_to(format!("{:?}", self.order_type)),
            pad_label("nonce", LABEL_LENGTH),
            color.apply_to(self.nonce),
            pad_label("maker", LABEL_LENGTH),
            color.apply_to(self.maker),
            pad_label("price", LABEL_LENGTH),
            color.apply_to(self.price),
            pad_label("currency", LABEL_LENGTH),
            color.apply_to(option_formatter(&self.currency)),
            pad_label("apr_bps", LABEL_LENGTH),
            color.apply_to(self.apr_bps),
            pad_label("duration_sec", LABEL_LENGTH),
            color.apply_to(self.duration_sec),
            pad_label("whitelist", LABEL_LENGTH),
            color.apply_to(self.whitelist),
            pad_label("maker_broker", LABEL_LENGTH),
            color.apply_to(option_formatter(&self.maker_broker)),
            pad_label("margin", LABEL_LENGTH),
            color.apply_to(option_formatter(&self.margin)),
            pad_label("expiry", LABEL_LENGTH),
            color.apply_to(format_timestamp(self.expiry)),
            pad_label("created_at", LABEL_LENGTH),
            color.apply_to(format_timestamp(self.created_at)),
            pad_label("updated_at", LABEL_LENGTH),
            color.apply_to(format_timestamp(self.updated_at)),
            pad_label("nfts_held", LABEL_LENGTH),
            color.apply_to(self.nfts_held),
            pad_label("vault_balance", LABEL_LENGTH),
            color.apply_to(self.vault_balance),
            pad_label("locked_at", LABEL_LENGTH),
            color.apply_to(format_timestamp(self.locked_at)),
            pad_label("locked_until", LABEL_LENGTH),
            color.apply_to(format_timestamp(self.locked_until)),
            pad_label("taker", LABEL_LENGTH),
            color.apply_to(option_formatter(&self.taker)),
            pad_label("collateral_returned", LABEL_LENGTH),
            color.apply_to(self.collateral_returned),
            pad_label("last_exercised_at", LABEL_LENGTH),
            color.apply_to(format_timestamp(self.last_exercised_at)),
            pad_label("exercise_count", LABEL_LENGTH),
            color.apply_to(self.exercise_count),
            pad_label("accumulated_profit", LABEL_LENGTH),
            color.apply_to(self.accumulated_profit),
            pad_label("taker_withdrawn_nfts", LABEL_LENGTH),
            color.apply_to(self.taker_withdrawn_nfts),
            pad_label("taker_withdrawn_funds", LABEL_LENGTH),
            color.apply_to(self.taker_withdrawn_funds),
            pad_label("early_close", LABEL_LENGTH),
            color.apply_to(self.early_close),
            pad_label("reserved0", LABEL_LENGTH),
            color.apply_to(if self.reserved0.iter().all(|&x| x == 0) {
                "[all zeros]".to_string()
            } else {
                "[non-zero]".to_string()
            }),
            pad_label("reserved1", LABEL_LENGTH),
            color.apply_to(if self.reserved1.iter().all(|&x| x == 0) {
                "[all zeros]".to_string()
            } else {
                "[non-zero]".to_string()
            }),
            pad_label("reserved2", LABEL_LENGTH),
            color.apply_to(if self.reserved2.iter().all(|&x| x == 0) {
                "[all zeros]".to_string()
            } else {
                "[non-zero]".to_string()
            })
        )
    }
}

impl CustomFormat for OrderNftReceipt {
    fn custom_format(&self) -> String {
        // Use the default text color but set this up for future use.
        let color = Style::new();

        format!(
            "{}
{}: {}
{}: {}
{}: {}
{}: {}",
            color.apply_to("OrderNftReceipt---------------"),
            pad_label("discriminator", LABEL_LENGTH),
            color.apply_to(hex::encode(self.discriminator)),
            pad_label("bump", LABEL_LENGTH),
            color.apply_to(self.bump),
            pad_label("asset", LABEL_LENGTH),
            color.apply_to(self.asset),
            pad_label("order_state", LABEL_LENGTH),
            color.apply_to(self.order_state)
        )
    }
}