@@ -22,14 +22,13 @@ use drift_program::{
2222// Reuses existing type definitions while removing Solana-specific abstractions
2323use crate :: types:: MarketState ;
2424
25- #[ repr( C , align( 16 ) ) ]
2625#[ derive( Clone , Copy , Debug , Default ) ]
27- pub struct IsolatedMarginCalculation {
28- pub market_index : u16 ,
26+ pub ( crate ) struct IsolatedMarginCalculation {
2927 pub margin_requirement : u128 ,
3028 pub total_collateral : i128 ,
3129 pub total_collateral_buffer : i128 ,
3230 pub margin_requirement_plus_buffer : u128 ,
31+ pub market_index : u16 ,
3332}
3433
3534impl IsolatedMarginCalculation {
@@ -57,10 +56,34 @@ impl IsolatedMarginCalculation {
5756 }
5857}
5958
59+ impl Into < crate :: types:: SimplifiedMarginCalculation > for SimplifiedMarginCalculation {
60+ fn into ( self ) -> crate :: types:: SimplifiedMarginCalculation {
61+ let mut isolated_margin_calculations =
62+ [ crate :: types:: IsolatedMarginCalculation :: default ( ) ; 8 ] ;
63+ for ( idx, p) in self . isolated_margin_calculations . iter ( ) . enumerate ( ) {
64+ isolated_margin_calculations[ idx] = crate :: types:: IsolatedMarginCalculation {
65+ margin_requirement : p. margin_requirement . into ( ) ,
66+ total_collateral : p. total_collateral . into ( ) ,
67+ total_collateral_buffer : p. total_collateral_buffer . into ( ) ,
68+ margin_requirement_plus_buffer : p. margin_requirement_plus_buffer . into ( ) ,
69+ market_index : p. market_index ,
70+ } ;
71+ }
72+ crate :: types:: SimplifiedMarginCalculation {
73+ total_collateral : self . total_collateral . into ( ) ,
74+ total_collateral_buffer : self . total_collateral_buffer . into ( ) ,
75+ margin_requirement : self . margin_requirement . into ( ) ,
76+ margin_requirement_plus_buffer : self . margin_requirement_plus_buffer . into ( ) ,
77+ isolated_margin_calculations,
78+ with_perp_isolated_liability : self . with_perp_isolated_liability ,
79+ with_spot_isolated_liability : self . with_spot_isolated_liability ,
80+ }
81+ }
82+ }
83+
6084// Core margin calculation result
61- #[ repr( C , align( 16 ) ) ]
6285#[ derive( Debug , Clone ) ]
63- pub struct SimplifiedMarginCalculation {
86+ pub ( crate ) struct SimplifiedMarginCalculation {
6487 pub total_collateral : i128 ,
6588 pub total_collateral_buffer : i128 ,
6689 pub margin_requirement : u128 ,
@@ -726,7 +749,7 @@ impl IncrementalMarginCalculation {
726749 margin_requirement : self . margin_requirement ,
727750 total_collateral_buffer : self . total_collateral_buffer ,
728751 margin_requirement_plus_buffer : self . margin_requirement_plus_buffer ,
729- isolated_margin_calculations : [ IsolatedMarginCalculation :: default ( ) ; 8 ] ,
752+ isolated_margin_calculations : [ Default :: default ( ) ; 8 ] ,
730753 with_perp_isolated_liability : false ,
731754 with_spot_isolated_liability : false ,
732755 }
0 commit comments