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
153
154
//! This module contains utility functions related openbook.
use crate::;
use ;
use ;
/// Converts a slice of `u64` values into a fixed-size byte array.
///
/// # Arguments
///
/// * `&self` - A reference to the `Market` struct.
/// * `slice` - A reference to a slice of `u64` values to be converted.
///
/// # Returns
///
/// A fixed-size array of bytes containing the serialized `u64` values.
///
/// # Examples
///
/// ```rust
/// use openbook::utils::u64_slice_to_pubkey;
///
/// let slice = [1, 2, 3, 4];
/// let pubkey = u64_slice_to_pubkey(slice);
/// ```
/// Reads a keypair from a file.
///
/// # Arguments
///
/// * `path` - The file path containing the keypair information.
///
/// # Returns
///
/// A `Keypair` instance created from the keypair information in the file.
///
/// # Examples
///
/// ```rust
/// use openbook::utils::read_keypair;
///
/// let path = String::from("/path/to/keypair_file.json");
/// // let keypair = read_keypair(&path);
/// ```
/// Gets the current UNIX timestamp in seconds.
///
/// # Returns
///
/// The current UNIX timestamp in seconds.
///
/// # Examples
///
/// ```rust
/// use openbook::utils::get_unix_secs;
///
/// let timestamp = get_unix_secs();
/// ```
/// Creates an `AccountInfo` instance from an `Account`.
///
/// # Arguments
///
/// * `account` - A mutable reference to the account from which to create `AccountInfo`.
/// * `key` - A reference to the public key associated with the account.
/// * `my_program_id` - A reference to the program's public key.
/// * `is_signer` - A boolean indicating whether the account is a signer.
/// * `is_writable` - A boolean indicating whether the account is writable.
///
/// # Returns
///
/// An `AccountInfo` instance created from the provided parameters.
///
/// # Examples
///
/// ```rust
/// use openbook::{pubkey::Pubkey, signature::Keypair, rpc_client::RpcClient};
/// use openbook::utils::{read_keypair, create_account_info_from_account};
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let rpc_url = std::env::var("RPC_URL").expect("RPC_URL is not set in .env file");
/// let key_path = std::env::var("KEY_PATH").expect("KEY_PATH is not set in .env file");
///
/// let rpc_client = RpcClient::new(rpc_url.clone());
///
/// let market_id = "8BnEgHoWFysVcuFFX7QztDmzuH8r5ZFvyP3sYwn1XTh6".parse()?;
///
/// let program_id = "srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"
/// .parse()
/// .unwrap();
///
/// let mut account = rpc_client.get_account(&market_id).await?;
///
/// let account_info = create_account_info_from_account(
/// &mut account,
/// &market_id,
/// &program_id,
/// false,
/// false,
/// );
///
/// println!("{:?}", account_info);
///
/// Ok(())
/// }
/// ```