Skip to content

Commit bddb41f

Browse files
committed
fix dup total_weight add
1 parent 222a335 commit bddb41f

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

programs/drift/src/state/lp_pool.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ impl<'a> AccountZeroCopyMut<'a, WeightDatum, ConstituentTargetWeightsFixed> {
490490
aum: u64,
491491
slot: u64,
492492
validation_flags: WeightValidationFlags,
493-
) -> DriftResult<()> {
493+
) -> DriftResult<i128> {
494494
let mut total_weight: i128 = 0;
495495
for (i, constituent_index) in constituents_indexes.iter().enumerate() {
496496
let mut target_amount = 0i128;
@@ -529,10 +529,6 @@ impl<'a> AccountZeroCopyMut<'a, WeightDatum, ConstituentTargetWeightsFixed> {
529529
return Err(ErrorCode::DefaultError);
530530
}
531531

532-
total_weight = total_weight
533-
.saturating_add(target_weight)
534-
.saturating_add(PERCENTAGE_PRECISION_I64 as i128);
535-
536532
let cell = self.get_mut(i as u32);
537533
cell.weight = target_weight as i64;
538534
cell.last_slot = slot;
@@ -548,7 +544,7 @@ impl<'a> AccountZeroCopyMut<'a, WeightDatum, ConstituentTargetWeightsFixed> {
548544
}
549545
}
550546

551-
Ok(())
547+
Ok(total_weight)
552548
}
553549
}
554550

programs/drift/src/state/lp_pool/tests.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ mod tests {
6565
_marker: PhantomData::<WeightDatum>,
6666
};
6767

68-
target_zc_mut
68+
let totalw = target_zc_mut
6969
.update_target_weights(
7070
&mapping_zc,
7171
&amm_inventory,
@@ -76,7 +76,8 @@ mod tests {
7676
WeightValidationFlags::NONE,
7777
)
7878
.unwrap();
79-
79+
80+
assert_eq!(totalw, 0);
8081
assert_eq!(target_zc_mut.len(), 1);
8182
assert_eq!(target_zc_mut.get(0).weight, 0);
8283
assert_eq!(target_zc_mut.get(0).last_slot, now_ts);
@@ -128,7 +129,7 @@ mod tests {
128129
_marker: PhantomData::<WeightDatum>,
129130
};
130131

131-
target_zc_mut
132+
let totalw = target_zc_mut
132133
.update_target_weights(
133134
&mapping_zc,
134135
&amm_inventory,
@@ -139,6 +140,8 @@ mod tests {
139140
WeightValidationFlags::NONE,
140141
)
141142
.unwrap();
143+
144+
assert_eq!(totalw, 1000000);
142145

143146
assert_eq!(target_zc_mut.len(), 1);
144147
assert_eq!(target_zc_mut.get(0).weight, PERCENTAGE_PRECISION_I64);

0 commit comments

Comments
 (0)