devol_accounts_kit/instructions_data/constructors/
fin_pool.rs1use std::error::Error;
2use crate::constants::FD;
3use crate::instructions_data::dvl_instruction_data::DvlInstructionData;
4use crate::instructions_data::fin_pool::{INSTRUCTION_FIN_POOL_VERSION, InstructionFinPool};
5use crate::instructions_data::instructions::Instructions;
6
7pub struct FinPoolParams {
8 pub price: f64,
9 pub terminate: bool,
10}
11
12impl<'a> DvlInstructionData<'a> for InstructionFinPool {
13 type DvlInstrParams = FinPoolParams;
14
15 fn new(params: Self::DvlInstrParams) -> Result<Box<InstructionFinPool>, Box<dyn Error>> {
16 Ok(Box::new(InstructionFinPool {
17 cmd: Instructions::FinPool as u8,
18 version: INSTRUCTION_FIN_POOL_VERSION,
19 reserved: [0; 5],
20 price: (params.price * FD) as i64,
21 terminate: params.terminate,
22 }))
23 }
24}
25
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30 use crate::instructions_data::constructors::fin_pool::FinPoolParams;
31 use crate::instructions_data::dvl_instruction_data::DvlInstruction;
32
33 #[test]
34 fn test_instruction_fin_pool_params() {
35 const TEST_PRICE: f64 = 10.;
36 const TEST_TERMINATE: bool = true;
37
38 let fin_pool_params = FinPoolParams {
39 price: TEST_PRICE,
40 terminate: TEST_TERMINATE,
41 };
42 let data = DvlInstruction::new::<InstructionFinPool>(fin_pool_params).unwrap();
43 assert_eq!(data.cmd, Instructions::FinPool as u8);
44 assert_eq!(data.version, INSTRUCTION_FIN_POOL_VERSION);
45 assert_eq!(data.price as f64 / FD, TEST_PRICE);
46 assert_eq!(data.terminate, TEST_TERMINATE);
47 }
48}