diff --git a/common/modules/farm/contexts/src/storage_cache.rs b/common/modules/farm/contexts/src/storage_cache.rs index 76f4cfc1d..e48e5fc85 100644 --- a/common/modules/farm/contexts/src/storage_cache.rs +++ b/common/modules/farm/contexts/src/storage_cache.rs @@ -41,7 +41,7 @@ impl<'a, C: FarmContracTraitBounds> StorageCache<'a, C> { } } -impl<'a, C: FarmContracTraitBounds> Drop for StorageCache<'a, C> { +impl Drop for StorageCache<'_, C> { fn drop(&mut self) { // commit changes to storage for the mutable fields self.sc_ref.reward_reserve().set(&self.reward_reserve); diff --git a/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_setup/mod.rs b/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_setup/mod.rs index d7cc9ab23..826d9ae78 100644 --- a/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_setup/mod.rs +++ b/dex/farm-with-locked-rewards/tests/farm_with_locked_rewards_setup/mod.rs @@ -305,7 +305,7 @@ where &self.energy_factory_wrapper, &rust_biguint!(0), |sc| { - sc.user_energy(&managed_address!(user)).set(&Energy::new( + sc.user_energy(&managed_address!(user)).set(Energy::new( BigInt::from(managed_biguint!(energy)), last_update_epoch, managed_biguint!(locked_tokens), diff --git a/dex/farm/tests/farm_setup/farm_rewards_distr_setup.rs b/dex/farm/tests/farm_setup/farm_rewards_distr_setup.rs index 23dada913..a6603a78d 100644 --- a/dex/farm/tests/farm_setup/farm_rewards_distr_setup.rs +++ b/dex/farm/tests/farm_setup/farm_rewards_distr_setup.rs @@ -121,7 +121,7 @@ where sc.farm_token().set_token_id(farm_token_id); sc.per_block_reward_amount() - .set(&to_managed_biguint(per_block_reward_amount)); + .set(to_managed_biguint(per_block_reward_amount)); sc.state().set(State::Active); sc.produce_rewards_enabled().set(true); diff --git a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs index e9ec051ca..bb790058b 100644 --- a/dex/farm/tests/farm_setup/multi_user_farm_setup.rs +++ b/dex/farm/tests/farm_setup/multi_user_farm_setup.rs @@ -271,7 +271,7 @@ where &self.energy_factory_wrapper, &rust_biguint!(0), |sc| { - sc.user_energy(&managed_address!(user)).set(&Energy::new( + sc.user_energy(&managed_address!(user)).set(Energy::new( BigInt::from(managed_biguint!(energy)), last_update_epoch, managed_biguint!(locked_tokens), diff --git a/dex/farm/tests/farm_single_user_test.rs b/dex/farm/tests/farm_single_user_test.rs index c2bede496..5f2586dcb 100644 --- a/dex/farm/tests/farm_single_user_test.rs +++ b/dex/farm/tests/farm_single_user_test.rs @@ -126,10 +126,8 @@ where let second_reward_share = DIVISION_SAFETY_CONSTANT * 10 * PER_BLOCK_REWARD_AMOUNT / current_farm_supply; let expected_reward_per_share = (first_reward_share * farm_in_amount - + second_reward_share * second_farm_in_amount - + total_amount - - 1) - / total_amount; + + second_reward_share * second_farm_in_amount) + .div_ceil(total_amount); farm_setup.enter_farm( second_farm_in_amount, @@ -174,10 +172,8 @@ fn test_exit_farm_after_enter_twice() { let second_reward_share = DIVISION_SAFETY_CONSTANT * 10 * PER_BLOCK_REWARD_AMOUNT / current_farm_supply; let prev_reward_per_share = (first_reward_share * farm_in_amount - + second_reward_share * second_farm_in_amount - + total_farm_token - - 1) - / total_farm_token; + + second_reward_share * second_farm_in_amount) + .div_ceil(total_farm_token); let new_reward_per_share = prev_reward_per_share + 25 * PER_BLOCK_REWARD_AMOUNT * DIVISION_SAFETY_CONSTANT / total_farm_token; let reward_per_share_diff = new_reward_per_share - prev_reward_per_share; diff --git a/dex/fuzz/src/fuzz_data.rs b/dex/fuzz/src/fuzz_data.rs index 35ad4e864..93e6e7bff 100644 --- a/dex/fuzz/src/fuzz_data.rs +++ b/dex/fuzz/src/fuzz_data.rs @@ -434,7 +434,7 @@ pub mod fuzz_data_tests { sc.farm_token().set_token_id(farm_token_id); sc.per_block_reward_amount() - .set(&to_managed_biguint(per_block_reward_amount)); + .set(to_managed_biguint(per_block_reward_amount)); sc.state().set(State::Active); sc.produce_rewards_enabled().set(true); diff --git a/dex/governance/tests/gov_tests.rs b/dex/governance/tests/gov_tests.rs index 1a05e7180..7a377e307 100644 --- a/dex/governance/tests/gov_tests.rs +++ b/dex/governance/tests/gov_tests.rs @@ -178,7 +178,7 @@ fn test_propose_bad_token() { }); }, ) - .assert_user_error(&String::from_utf8(UNREGISTERED_TOKEN_ID.to_vec()).unwrap()); + .assert_user_error(core::str::from_utf8(UNREGISTERED_TOKEN_ID).unwrap()); } #[test] @@ -200,7 +200,7 @@ fn test_propose_bad_amount() { }); }, ) - .assert_user_error(&String::from_utf8(NOT_ENOUGH_FUNDS_TO_PROPOSE.to_vec()).unwrap()); + .assert_user_error(core::str::from_utf8(NOT_ENOUGH_FUNDS_TO_PROPOSE).unwrap()); } #[test] @@ -418,7 +418,7 @@ fn test_basic_reclaim() { sc.redeem(); }, ) - .assert_user_error(&String::from_utf8(VOTING_PERIOD_NOT_ENDED.to_vec()).unwrap()); + .assert_user_error(core::str::from_utf8(VOTING_PERIOD_NOT_ENDED).unwrap()); gov_setup .blockchain_wrapper @@ -495,7 +495,7 @@ fn test_vote() { sc.upvote(0); }, ) - .assert_user_error(&String::from_utf8(PROPOSAL_NOT_ACTIVE.to_vec()).unwrap()); + .assert_user_error(core::str::from_utf8(PROPOSAL_NOT_ACTIVE).unwrap()); gov_setup .blockchain_wrapper @@ -565,7 +565,7 @@ fn test_vote() { sc.redeem(); }, ) - .assert_user_error(&String::from_utf8(VOTING_PERIOD_NOT_ENDED.to_vec()).unwrap()); + .assert_user_error(core::str::from_utf8(VOTING_PERIOD_NOT_ENDED).unwrap()); gov_setup .blockchain_wrapper diff --git a/dex/pair/src/contexts/base.rs b/dex/pair/src/contexts/base.rs index 751ca7fc1..94ff5c292 100644 --- a/dex/pair/src/contexts/base.rs +++ b/dex/pair/src/contexts/base.rs @@ -97,7 +97,7 @@ where } } -impl<'a, C> Drop for StorageCache<'a, C> +impl Drop for StorageCache<'_, C> where C: crate::config::ConfigModule, { diff --git a/dex/router/src/contract.rs b/dex/router/src/contract.rs index f879e36e6..800a20b91 100644 --- a/dex/router/src/contract.rs +++ b/dex/router/src/contract.rs @@ -39,7 +39,7 @@ pub trait Router: self.pair_creation_enabled().set_if_empty(false); self.init_factory(pair_template_address_opt.into_option()); - self.owner().set(&self.blockchain().get_caller()); + self.owner().set(self.blockchain().get_caller()); } #[upgrade] diff --git a/energy-integration/energy-factory-mock/src/lib.rs b/energy-integration/energy-factory-mock/src/lib.rs index d3354e67e..9ed54cc6c 100644 --- a/energy-integration/energy-factory-mock/src/lib.rs +++ b/energy-integration/energy-factory-mock/src/lib.rs @@ -17,7 +17,7 @@ pub trait EnergyFactoryMock { total_locked_tokens: BigUint, ) { let current_epoch = self.blockchain().get_block_epoch(); - self.user_energy(&user).set(&Energy::new( + self.user_energy(&user).set(Energy::new( BigInt::from(energy_amount), current_epoch, total_locked_tokens, diff --git a/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs b/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs index 93e6da275..1f1a09b48 100644 --- a/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs +++ b/energy-integration/fees-collector/tests/fees_collector_test_setup/mod.rs @@ -253,7 +253,7 @@ where &self.energy_factory_wrapper, &rust_biguint!(0), |sc| { - sc.user_energy(&managed_address!(user)).set(&Energy::new( + sc.user_energy(&managed_address!(user)).set(Energy::new( BigInt::from(managed_biguint!(energy_amount)), current_epoch, managed_biguint!(total_locked_tokens), diff --git a/energy-integration/governance-v2/src/configurable.rs b/energy-integration/governance-v2/src/configurable.rs index 12751ce7f..b74f83b0b 100644 --- a/energy-integration/governance-v2/src/configurable.rs +++ b/energy-integration/governance-v2/src/configurable.rs @@ -2,33 +2,32 @@ use crate::errors::ERROR_NOT_AN_ESDT; multiversx_sc::imports!(); -/// # MultiversX smart contract module - Governance -/// -/// This is a standard smart contract module, that when added to a smart contract offers governance features: -/// - proposing actions -/// - voting/downvoting a certain proposal -/// - after a voting period, either putting the action in a queue (if it reached quorum), or canceling -/// -/// Voting is done through energy. -/// -/// The module provides the following configurable parameters: -/// - `minEnergyForPropose` - the minimum energy required for submitting a proposal -/// - `quorum` - the minimum number of (`votes` minus `downvotes`) at the end of voting period -/// - `maxActionsPerProposal` - Maximum number of actions (transfers and/or smart contract calls) that a proposal may have -/// - `votingDelayInBlocks` - Number of blocks to wait after a block is proposed before being able to vote/downvote that proposal -/// - `votingPeriodInBlocks` - Number of blocks the voting period lasts (voting delay does not count towards this) -/// - `lockTimeAfterVotingEndsInBlocks` - Number of blocks to wait before a successful proposal can be executed -/// -/// The module also provides events for most actions that happen: -/// - `proposalCreated` - triggers when a proposal is created. Also provoides all the relevant information, like proposer, actions etc. -/// - `voteCast` - user voted on a proposal -/// - `downvoteCast` - user downvoted a proposal -/// - `proposalCanceled`, `proposalQueued` and `proposalExecuted` - provides the ID of the specific proposal -/// - `userDeposit` - a user deposited some tokens needed for a future payable action -/// -/// Please note that although the main contract can modify the module's storage directly, it is not recommended to do so, -/// as that defeats the whole purpose of having governance. These parameters should only be modified through actions. -/// +// # MultiversX smart contract module - Governance +// +// This is a standard smart contract module, that when added to a smart contract offers governance features: +// - proposing actions +// - voting/downvoting a certain proposal +// - after a voting period, either putting the action in a queue (if it reached quorum), or canceling +// +// Voting is done through energy. +// +// The module provides the following configurable parameters: +// - `minEnergyForPropose` - the minimum energy required for submitting a proposal +// - `quorum` - the minimum number of (`votes` minus `downvotes`) at the end of voting period +// - `maxActionsPerProposal` - Maximum number of actions (transfers and/or smart contract calls) that a proposal may have +// - `votingDelayInBlocks` - Number of blocks to wait after a block is proposed before being able to vote/downvote that proposal +// - `votingPeriodInBlocks` - Number of blocks the voting period lasts (voting delay does not count towards this) +// - `lockTimeAfterVotingEndsInBlocks` - Number of blocks to wait before a successful proposal can be executed +// +// The module also provides events for most actions that happen: +// - `proposalCreated` - triggers when a proposal is created. Also provoides all the relevant information, like proposer, actions etc. +// - `voteCast` - user voted on a proposal +// - `downvoteCast` - user downvoted a proposal +// - `proposalCanceled`, `proposalQueued` and `proposalExecuted` - provides the ID of the specific proposal +// - `userDeposit` - a user deposited some tokens needed for a future payable action +// +// Please note that although the main contract can modify the module's storage directly, it is not recommended to do so, +// as that defeats the whole purpose of having governance. These parameters should only be modified through actions. const MIN_VOTING_DELAY: u64 = 1; const MAX_VOTING_DELAY: u64 = 100_800; // 1 Week diff --git a/energy-integration/governance-v2/tests/gov_test_setup/mod.rs b/energy-integration/governance-v2/tests/gov_test_setup/mod.rs index 465222293..4809577bf 100644 --- a/energy-integration/governance-v2/tests/gov_test_setup/mod.rs +++ b/energy-integration/governance-v2/tests/gov_test_setup/mod.rs @@ -79,25 +79,25 @@ where .execute_tx(&owner, &energy_factory_wrapper, &rust_zero, |sc| { sc.init(); sc.user_energy(&managed_address!(&first_user)) - .set(&Energy::new( + .set(Energy::new( BigInt::from(managed_biguint!(USER_ENERGY)), 0, managed_biguint!(0), )); sc.user_energy(&managed_address!(&second_user)) - .set(&Energy::new( + .set(Energy::new( BigInt::from(managed_biguint!(USER_ENERGY)), 0, managed_biguint!(0), )); sc.user_energy(&managed_address!(&third_user)) - .set(&Energy::new( + .set(Energy::new( BigInt::from(managed_biguint!(USER_ENERGY + 210_000)), 0, managed_biguint!(0), )); sc.user_energy(&managed_address!(&no_energy_user)) - .set(&Energy::new( + .set(Energy::new( BigInt::from(managed_biguint!(0)), 0, managed_biguint!(0), diff --git a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs index c0d4ec4d3..640af81b4 100644 --- a/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs +++ b/farm-staking/farm-staking-proxy/tests/staking_farm_with_lp_staking_contract_interactions/mod.rs @@ -760,7 +760,7 @@ where &self.energy_factory_wrapper, &rust_biguint!(0), |sc| { - sc.user_energy(&managed_address!(user)).set(&Energy::new( + sc.user_energy(&managed_address!(user)).set(Energy::new( BigInt::from(managed_biguint!(energy)), last_update_epoch, managed_biguint!(locked_tokens), diff --git a/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs b/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs index 7a46618cd..66235a25a 100644 --- a/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs +++ b/farm-staking/farm-staking/tests/farm_staking_setup/mod.rs @@ -785,7 +785,7 @@ where &self.energy_factory_wrapper, &rust_biguint!(0), |sc| { - sc.user_energy(&managed_address!(user)).set(&Energy::new( + sc.user_energy(&managed_address!(user)).set(Energy::new( BigInt::from(managed_biguint!(energy)), last_update_epoch, managed_biguint!(locked_tokens), diff --git a/farm-staking/farm-staking/tests/farm_staking_test.rs b/farm-staking/farm-staking/tests/farm_staking_test.rs index 4e00cfdef..4f2471fde 100644 --- a/farm-staking/farm-staking/tests/farm_staking_test.rs +++ b/farm-staking/farm-staking/tests/farm_staking_test.rs @@ -203,10 +203,8 @@ where let first_reward_share = 0; let second_reward_share = 400_000; let expected_reward_per_share = (first_reward_share * farm_in_amount - + second_reward_share * second_farm_in_amount - + total_amount - - 1) - / total_amount; + + second_reward_share * second_farm_in_amount) + .div_ceil(total_amount); farm_setup.stake_farm( &user_address,