-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathinstruction.rs
185 lines (174 loc) · 6.3 KB
/
instruction.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
use {
crate::{
c_oracle_header::PC_VERSION,
deserialize::load,
error::OracleError,
},
bytemuck::{
Pod,
Zeroable,
},
num_derive::{
FromPrimitive,
ToPrimitive,
},
num_traits::FromPrimitive,
solana_program::pubkey::Pubkey,
};
/// WARNING : NEW COMMANDS SHOULD BE ADDED AT THE END OF THE LIST
#[repr(i32)]
#[derive(PartialEq, Eq, FromPrimitive, ToPrimitive)]
pub enum OracleCommand {
/// Initialize first mapping list account
// account[0] funding account [signer writable]
// account[1] mapping account [signer writable]
InitMapping = 0,
/// Initialize and add new mapping account
// account[0] funding account [signer writable]
// account[1] tail mapping account [signer writable]
// account[2] new mapping account [signer writable]
AddMapping = 1,
/// Initialize and add new product reference data account
// account[0] funding account [signer writable]
// account[1] mapping account [signer writable]
// account[2] new product account [signer writable]
AddProduct = 2,
/// Update product account
// account[0] funding account [signer writable]
// account[1] product account [signer writable]
UpdProduct = 3,
/// Add new price account to a product account
// account[0] funding account [signer writable]
// account[1] product account [writable]
// account[2] new price account [writable]
// account[3] permissions account [writable]
AddPrice = 4,
/// Add publisher to symbol account
// account[0] funding account [signer writable]
// account[1] price account [signer writable]
AddPublisher = 5,
/// Delete publisher from symbol account
// account[0] funding account [signer writable]
// account[1] price account [signer writable]
DelPublisher = 6,
/// Publish component price
// account[0] funding account [signer writable]
// account[1] price account [writable]
// account[2] sysvar_clock account []
UpdPrice = 7,
/// Compute aggregate price
// account[0] funding account [signer writable]
// account[1] price account [writable]
// account[2] sysvar_clock account []
AggPrice = 8,
/// (Re)initialize price account
// account[0] funding account [signer writable]
// account[1] new price account [signer writable]
InitPrice = 9,
/// deprecated
InitTest = 10,
/// deprecated
UpdTest = 11,
/// Set min publishers
// account[0] funding account [signer writable]
// account[1] price account [signer writable]
SetMinPub = 12,
/// Publish component price, never returning an error even if the update failed
// account[0] funding account [signer writable]
// account[1] price account [writable]
// account[2] sysvar_clock account []
UpdPriceNoFailOnError = 13,
/// Resizes a price account so that it fits the Time Machine
// account[0] funding account [signer writable]
// account[1] price account [signer writable]
// account[2] system program []
ResizePriceAccount = 14,
/// Deletes a price account
// account[0] funding account [signer writable]
// account[1] product account [signer writable]
// account[2] price account [signer writable]
DelPrice = 15,
/// Deletes a product account
// key[0] funding account [signer writable]
// key[1] mapping account [signer writable]
// key[2] product account [signer writable]
DelProduct = 16,
/// Update authorities
// key[0] upgrade authority [signer writable]
// key[1] programdata account []
// key[2] permissions account [writable]
// key[3] system program []
UpdPermissions = 17,
/// Set max latency
// account[0] funding account [signer writable]
// account[1] price account [signer writable]
SetMaxLatency = 18,
/// Init price feed index
// account[0] funding account [signer writable]
// account[1] price account [writable]
// account[2] permissions account [writable]
InitPriceFeedIndex = 19,
// account[0] funding account [signer writable]
// account[1] mapping account [writable]
ResizeMapping = 20,
}
#[repr(C)]
#[derive(Zeroable, Pod, Copy, Clone)]
pub struct CommandHeader {
pub version: u32,
pub command: i32,
}
pub fn load_command_header_checked(data: &[u8]) -> Result<OracleCommand, OracleError> {
let command_header = load::<CommandHeader>(data)?;
if command_header.version != PC_VERSION {
return Err(OracleError::InvalidInstructionVersion);
}
OracleCommand::from_i32(command_header.command).ok_or(OracleError::UnrecognizedInstruction)
}
#[repr(C)]
#[derive(Zeroable, Pod, Copy, Clone)]
pub struct AddPriceArgs {
pub header: CommandHeader,
pub exponent: i32,
pub price_type: u32,
}
pub type InitPriceArgs = AddPriceArgs;
#[repr(C)]
#[derive(Zeroable, Pod, Copy, Clone)]
pub struct AddPublisherArgs {
pub header: CommandHeader,
pub publisher: Pubkey,
}
pub type DelPublisherArgs = AddPublisherArgs;
#[repr(C)]
#[derive(Zeroable, Clone, Copy, Pod)]
pub struct SetMinPubArgs {
pub header: CommandHeader,
pub minimum_publishers: u8,
pub unused_: [u8; 3],
}
#[repr(C)]
#[derive(Zeroable, Pod, Copy, Clone)]
pub struct UpdPriceArgs {
pub header: CommandHeader,
pub status: u32,
pub unused_: u32,
pub price: i64,
pub confidence: u64,
pub publishing_slot: u64,
}
#[repr(C)]
#[derive(Zeroable, Pod, Copy, Clone)]
pub struct UpdPermissionsArgs {
pub header: CommandHeader,
pub master_authority: Pubkey,
pub data_curation_authority: Pubkey,
pub security_authority: Pubkey,
}
#[repr(C)]
#[derive(Zeroable, Clone, Copy, Pod)]
pub struct SetMaxLatencyArgs {
pub header: CommandHeader,
pub max_latency: u8,
pub unused_: [u8; 3],
}