Skip to content

Commit 6417a83

Browse files
authored
fix reward variable (#770)
* fix reward variable * remove duplicate to_owned * clippy * total_withdrawn_reward not mutable
1 parent 9bf1101 commit 6417a83

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

asset-registry/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Older clippy versions give a false positive on the expansion of [pallet::call].
33
// This is fixed in https://github.com/rust-lang/rust-clippy/issues/8321
44
#![allow(clippy::large_enum_variant)]
5+
#![allow(clippy::too_many_arguments)]
6+
57
use frame_support::{pallet_prelude::*, traits::EnsureOriginWithArg, transactional};
68
use frame_system::pallet_prelude::*;
79
pub use orml_traits::asset_registry::AssetMetadata;
@@ -140,7 +142,6 @@ pub mod module {
140142
Self::do_register_asset(metadata, asset_id)
141143
}
142144

143-
#[allow(clippy::too_many_arguments)]
144145
#[pallet::weight(T::WeightInfo::update_asset())]
145146
#[transactional]
146147
pub fn update_asset(

rewards/src/lib.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#![allow(clippy::unused_unit)]
21
#![cfg_attr(not(feature = "std"), no_std)]
2+
#![allow(clippy::unused_unit)]
3+
#![allow(clippy::too_many_arguments)]
34

45
mod mock;
56
mod tests;
@@ -275,8 +276,8 @@ impl<T: Config> Pallet<T> {
275276
Self::claim_one(
276277
withdrawn_rewards,
277278
*reward_currency,
278-
share,
279-
total_reward,
279+
share.to_owned(),
280+
total_reward.to_owned(),
280281
total_shares,
281282
total_withdrawn_reward,
282283
who,
@@ -302,8 +303,8 @@ impl<T: Config> Pallet<T> {
302303
Self::claim_one(
303304
withdrawn_rewards,
304305
reward_currency,
305-
share,
306-
total_reward,
306+
share.to_owned(),
307+
total_reward.to_owned(),
307308
total_shares,
308309
total_withdrawn_reward,
309310
who,
@@ -315,12 +316,11 @@ impl<T: Config> Pallet<T> {
315316
});
316317
}
317318

318-
#[allow(clippy::too_many_arguments)] // just we need to have all these to do the stuff
319319
fn claim_one(
320320
withdrawn_rewards: &mut BTreeMap<T::CurrencyId, T::Balance>,
321321
reward_currency: T::CurrencyId,
322-
share: &mut T::Share,
323-
total_reward: &mut T::Balance,
322+
share: T::Share,
323+
total_reward: T::Balance,
324324
total_shares: U256,
325325
total_withdrawn_reward: &mut T::Balance,
326326
who: &T::AccountId,
@@ -332,7 +332,7 @@ impl<T: Config> Pallet<T> {
332332
total_reward,
333333
total_shares,
334334
withdrawn_reward,
335-
total_withdrawn_reward,
335+
total_withdrawn_reward.to_owned(),
336336
);
337337
if !reward_to_withdraw.is_zero() {
338338
*total_withdrawn_reward = total_withdrawn_reward.saturating_add(reward_to_withdraw);
@@ -344,20 +344,20 @@ impl<T: Config> Pallet<T> {
344344
}
345345

346346
fn reward_to_withdraw(
347-
share: &mut T::Share,
348-
total_reward: &mut T::Balance,
347+
share: T::Share,
348+
total_reward: T::Balance,
349349
total_shares: U256,
350350
withdrawn_reward: T::Balance,
351-
total_withdrawn_reward: &mut T::Balance,
351+
total_withdrawn_reward: T::Balance,
352352
) -> T::Balance {
353-
let total_reward_proportion: T::Balance = U256::from(share.to_owned().saturated_into::<u128>())
354-
.saturating_mul(U256::from(total_reward.to_owned().saturated_into::<u128>()))
353+
let total_reward_proportion: T::Balance = U256::from(share.saturated_into::<u128>())
354+
.saturating_mul(U256::from(total_reward.saturated_into::<u128>()))
355355
.checked_div(total_shares)
356356
.unwrap_or_default()
357357
.as_u128()
358358
.unique_saturated_into();
359359
total_reward_proportion
360360
.saturating_sub(withdrawn_reward)
361-
.min(total_reward.saturating_sub(*total_withdrawn_reward))
361+
.min(total_reward.saturating_sub(total_withdrawn_reward))
362362
}
363363
}

0 commit comments

Comments
 (0)