Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ missing_errors_doc = "allow"
must_use_candidate = "allow"
identity_op = "allow"
tabs_in_doc_comments = "allow"
redundant_clone = "warn"
redundant_clone = "deny"
missing-const-for-fn = "warn"

[workspace.lints.rust]
unreachable_patterns = "deny"
Expand Down
2 changes: 1 addition & 1 deletion pallets/dispenser/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct CheckNonce<T: Config>(#[codec(compact)] pub T::Nonce);

impl<T: Config> CheckNonce<T> {
/// utility constructor. Used only in client/factory code.
pub fn from(nonce: T::Nonce) -> Self {
pub const fn from(nonce: T::Nonce) -> Self {
Self(nonce)
}
}
Expand Down
6 changes: 3 additions & 3 deletions pallets/funding/src/functions/1_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ impl<T: Config> Pallet<T> {
project_metadata.minimum_price.checked_mul_int(total_allocation_size).ok_or(Error::<T>::BadMath)?;

let project_details = ProjectDetails {
issuer_account: issuer.clone(),
issuer_did: did.clone(),
issuer_account: issuer,
issuer_did: did,
is_frozen: false,
fundraising_target_usd: fundraising_target,
status: ProjectStatus::Application,
Expand Down Expand Up @@ -110,7 +110,7 @@ impl<T: Config> Pallet<T> {

// * Calculate new variables *
let (project_details, bucket) =
Self::project_validation(&new_project_metadata, issuer.clone(), project_details.issuer_did.clone())?;
Self::project_validation(&new_project_metadata, issuer.clone(), project_details.issuer_did)?;

// * Update storage *
ProjectsMetadata::<T>::insert(project_id, new_project_metadata.clone());
Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/functions/3_auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl<T: Config> Pallet<T> {

Self::deposit_event(Event::Bid {
project_id,
bidder: bidder.clone(),
bidder,
id: bid_id,
ct_amount,
ct_price: ct_usd_price,
Expand Down
4 changes: 2 additions & 2 deletions pallets/funding/src/functions/5_settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<T: Config> Pallet<T> {
T::ContributionTokenCurrency::create(project_id, escrow_account.clone(), false, 1_u32.into())?;
T::ContributionTokenCurrency::set(
project_id,
&escrow_account.clone(),
&escrow_account,
token_information.name.into(),
token_information.symbol.into(),
token_information.decimals,
Expand Down Expand Up @@ -390,7 +390,7 @@ impl<T: Config> Pallet<T> {
Fortitude::Force,
)?;

T::OnSlash::on_slash(&evaluation.evaluator, slashed_amount);
T::OnSlash::on_slash(&evaluation.evaluator, &slashed_amount);

Ok(evaluation.current_plmc_bond.saturating_sub(slashed_amount))
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/functions/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl<T: Config> Pallet<T> {
polimec_account: AccountIdOf<T>,
project_id: ProjectId,
) -> bool {
let message_to_sign = Self::get_substrate_message_to_sign(polimec_account.clone(), project_id).unwrap();
let message_to_sign = Self::get_substrate_message_to_sign(polimec_account, project_id).unwrap();
let message_bytes = message_to_sign.into_bytes();
let signature = SrSignature::from_slice(&signature_bytes[..64]).unwrap();
let public = SrPublic::from_slice(&expected_substrate_account).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions pallets/funding/src/instantiator/calculations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl<
) -> Vec<UserToPLMCBalance<T>> {
let mut output = Vec::new();
let charged_bids = self.get_actual_price_charged_for_bucketed_bids(bids, project_metadata.clone(), None);
let grouped_by_price_bids = charged_bids.clone().into_iter().group_by(|&(_, price)| price);
let grouped_by_price_bids = charged_bids.into_iter().group_by(|&(_, price)| price);
let mut grouped_by_price_bids: Vec<(PriceOf<T>, Vec<BidParams<T>>)> = grouped_by_price_bids
.into_iter()
.map(|(key, group)| (key, group.map(|(bid, _price_)| bid).collect()))
Expand Down Expand Up @@ -208,7 +208,7 @@ impl<
) -> Vec<UserToFundingAsset<T>> {
let mut output = Vec::new();
let charged_bids = self.get_actual_price_charged_for_bucketed_bids(bids, project_metadata.clone(), None);
let grouped_by_price_bids = charged_bids.clone().into_iter().group_by(|&(_, price)| price);
let grouped_by_price_bids = charged_bids.into_iter().group_by(|&(_, price)| price);
let mut grouped_by_price_bids: Vec<(PriceOf<T>, Vec<BidParams<T>>)> = grouped_by_price_bids
.into_iter()
.map(|(key, group)| (key, group.map(|(bid, _price)| bid).collect()))
Expand Down Expand Up @@ -499,7 +499,7 @@ impl<
bucket.update(ct_min_ticket);
}

self.generate_bids_from_bucket(project_metadata.clone(), bucket, AcceptedFundingAsset::USDT)
self.generate_bids_from_bucket(project_metadata, bucket, AcceptedFundingAsset::USDT)
}

pub fn generate_bids_from_total_ct_percent(
Expand Down
33 changes: 13 additions & 20 deletions pallets/funding/src/instantiator/chain_interactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl<
RuntimeEvent: From<Event<T>> + TryInto<Event<T>> + Parameter + Member + IsType<<T as frame_system::Config>::RuntimeEvent>,
> Instantiator<T, AllPalletsWithoutSystem, RuntimeEvent>
{
pub fn new(ext: OptionalExternalities) -> Self {
pub const fn new(ext: OptionalExternalities) -> Self {
Self { ext, nonce: RefCell::new(0u64), _marker: PhantomData }
}

Expand Down Expand Up @@ -447,7 +447,7 @@ impl<
}

pub fn mint_necessary_tokens_for_evaluations(&mut self, evaluations: Vec<EvaluationParams<T>>) {
let plmc_required = self.calculate_evaluation_plmc_spent(evaluations.clone());
let plmc_required = self.calculate_evaluation_plmc_spent(evaluations);
self.mint_plmc_ed_if_required(plmc_required.accounts());
self.mint_plmc_to(plmc_required);
}
Expand Down Expand Up @@ -684,7 +684,7 @@ impl<
issuer: AccountIdOf<T>,
maybe_did: Option<Did>,
) -> ProjectId {
let project_id = self.create_new_project(project_metadata, issuer.clone(), maybe_did);
let project_id = self.create_new_project(project_metadata, issuer, maybe_did);
assert_eq!(self.go_to_next_state(project_id), ProjectStatus::EvaluationRound);

project_id
Expand All @@ -697,15 +697,14 @@ impl<
maybe_did: Option<Did>,
evaluations: Vec<EvaluationParams<T>>,
) -> ProjectId {
let project_id = self.create_evaluating_project(project_metadata, issuer.clone(), maybe_did);
let project_id = self.create_evaluating_project(project_metadata, issuer, maybe_did);

let evaluators = evaluations.accounts();
self.mint_plmc_ed_if_required(evaluators.clone());

let prev_supply = self.get_plmc_total_supply();
let prev_free_plmc_balances = self.get_free_plmc_balances_for(evaluators.clone());
let prev_held_plmc_balances =
self.get_reserved_plmc_balances_for(evaluators.clone(), HoldReason::Evaluation.into());
let prev_held_plmc_balances = self.get_reserved_plmc_balances_for(evaluators, HoldReason::Evaluation.into());

let plmc_evaluation_deposits: Vec<UserToPLMCBalance<T>> =
self.calculate_evaluation_plmc_spent(evaluations.clone());
Expand All @@ -716,11 +715,10 @@ impl<

let expected_free_plmc_balances = prev_free_plmc_balances;
let expected_held_plmc_balances = self.generic_map_operation(
vec![prev_held_plmc_balances.clone(), plmc_evaluation_deposits.clone()],
vec![prev_held_plmc_balances, plmc_evaluation_deposits.clone()],
MergeOperation::Add,
);
let expected_total_plmc_supply =
prev_supply + self.sum_balance_mappings(vec![plmc_evaluation_deposits.clone()]);
let expected_total_plmc_supply = prev_supply + self.sum_balance_mappings(vec![plmc_evaluation_deposits]);

self.evaluation_assertions(
project_id,
Expand Down Expand Up @@ -757,15 +755,15 @@ impl<
let plmc_evaluation_deposits: Vec<UserToPLMCBalance<T>> = self.calculate_evaluation_plmc_spent(evaluations);
let plmc_bid_deposits: Vec<UserToPLMCBalance<T>> = self
.calculate_auction_plmc_charged_from_all_bids_made_or_with_bucket(&bids, project_metadata.clone(), None);
let reducible_evaluator_balances = self.slash_evaluator_balances(plmc_evaluation_deposits.clone());
let reducible_evaluator_balances = self.slash_evaluator_balances(plmc_evaluation_deposits);

let necessary_plmc_mints = self.generic_map_operation(
vec![plmc_bid_deposits.clone(), reducible_evaluator_balances],
MergeOperation::Subtract,
);
let funding_asset_deposits = self.calculate_auction_funding_asset_charged_from_all_bids_made_or_with_bucket(
&bids,
project_metadata.clone(),
project_metadata,
None,
);

Expand All @@ -774,8 +772,8 @@ impl<
self.generic_map_operation(vec![prev_held_plmc_balances, plmc_bid_deposits], MergeOperation::Add);
let expected_plmc_supply = prev_plmc_supply + necessary_plmc_mints.total();

self.mint_plmc_to(necessary_plmc_mints.clone());
self.mint_funding_asset_to(funding_asset_deposits.clone());
self.mint_plmc_to(necessary_plmc_mints);
self.mint_funding_asset_to(funding_asset_deposits);

self.bid_for_users(project_id, bids.clone()).unwrap();

Expand Down Expand Up @@ -805,13 +803,8 @@ impl<
bids: Vec<BidParams<T>>,
mark_as_settled: bool,
) -> ProjectId {
let project_id = self.create_finished_project(
project_metadata.clone(),
issuer.clone(),
maybe_did,
evaluations.clone(),
bids.clone(),
);
let project_id =
self.create_finished_project(project_metadata.clone(), issuer, maybe_did, evaluations, bids.clone());

assert!(matches!(self.go_to_next_state(project_id), ProjectStatus::SettlementStarted(_)));
self.test_ct_created_for(project_id);
Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/instantiator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#[allow(clippy::wildcard_imports)]

extern crate alloc;

use crate::{traits::*, *};
Expand Down
20 changes: 10 additions & 10 deletions pallets/funding/src/instantiator/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct UserToPLMCBalance<T: Config> {
pub plmc_amount: Balance,
}
impl<T: Config> UserToPLMCBalance<T> {
pub fn new(account: AccountIdOf<T>, plmc_amount: Balance) -> Self {
pub const fn new(account: AccountIdOf<T>, plmc_amount: Balance) -> Self {
Self { account, plmc_amount }
}
}
Expand Down Expand Up @@ -101,7 +101,7 @@ pub struct EvaluationParams<T: Config> {
pub receiving_account: Junction,
}
impl<T: Config> EvaluationParams<T> {
pub fn new(account: AccountIdOf<T>, usd_amount: Balance, receiving_account: Junction) -> Self {
pub const fn new(account: AccountIdOf<T>, usd_amount: Balance, receiving_account: Junction) -> Self {
EvaluationParams::<T> { account, usd_amount, receiving_account }
}
}
Expand Down Expand Up @@ -137,7 +137,7 @@ pub struct UserToUSDAmount<T: Config> {
pub usd_amount: Balance,
}
impl<T: Config> UserToUSDAmount<T> {
pub fn new(account: AccountIdOf<T>, usd_amount: Balance) -> Self {
pub const fn new(account: AccountIdOf<T>, usd_amount: Balance) -> Self {
Self { account, usd_amount }
}
}
Expand Down Expand Up @@ -195,7 +195,7 @@ pub struct UserToFundingAsset<T: Config> {
pub asset_id: AssetIdOf<T>,
}
impl<T: Config> UserToFundingAsset<T> {
pub fn new(account: AccountIdOf<T>, asset_amount: Balance, asset_id: AssetIdOf<T>) -> Self {
pub const fn new(account: AccountIdOf<T>, asset_amount: Balance, asset_id: AssetIdOf<T>) -> Self {
Self { account, asset_amount, asset_id }
}
}
Expand Down Expand Up @@ -298,7 +298,7 @@ pub struct BidParams<T: Config> {
pub receiving_account: Junction,
}
impl<T: Config> BidParams<T> {
pub fn new(
pub const fn new(
bidder: AccountIdOf<T>,
investor_type: InvestorType,
amount: Balance,
Expand All @@ -319,7 +319,7 @@ impl<T: Config> From<(AccountIdOf<T>, Balance)> for BidParams<T> {
asset: AcceptedFundingAsset::USDT,
receiving_account: Junction::AccountId32 {
network: Some(NetworkId::Polkadot),
id: T::AccountId32Conversion::convert(bidder.clone()),
id: T::AccountId32Conversion::convert(bidder),
},
}
}
Expand All @@ -334,7 +334,7 @@ impl<T: Config> From<(AccountIdOf<T>, InvestorType, Balance)> for BidParams<T> {
asset: AcceptedFundingAsset::USDT,
receiving_account: Junction::AccountId32 {
network: Some(NetworkId::Polkadot),
id: T::AccountId32Conversion::convert(bidder.clone()),
id: T::AccountId32Conversion::convert(bidder),
},
}
}
Expand All @@ -349,7 +349,7 @@ impl<T: Config> From<(AccountIdOf<T>, InvestorType, Balance, ParticipationMode)>
asset: AcceptedFundingAsset::USDT,
receiving_account: Junction::AccountId32 {
network: Some(NetworkId::Polkadot),
id: T::AccountId32Conversion::convert(bidder.clone()),
id: T::AccountId32Conversion::convert(bidder),
},
}
}
Expand All @@ -366,7 +366,7 @@ impl<T: Config> From<(AccountIdOf<T>, InvestorType, Balance, AcceptedFundingAsse
asset,
receiving_account: Junction::AccountId32 {
network: Some(NetworkId::Polkadot),
id: T::AccountId32Conversion::convert(bidder.clone()),
id: T::AccountId32Conversion::convert(bidder),
},
}
}
Expand All @@ -391,7 +391,7 @@ impl<T: Config> From<(AccountIdOf<T>, InvestorType, Balance, ParticipationMode,
asset,
receiving_account: Junction::AccountId32 {
network: Some(NetworkId::Polkadot),
id: T::AccountId32Conversion::convert(bidder.clone()),
id: T::AccountId32Conversion::convert(bidder),
},
}
}
Expand Down
12 changes: 6 additions & 6 deletions pallets/funding/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,22 +525,22 @@ pub mod inner {
pub usd_maximum_per_did: Option<Balance>,
}
impl TicketSize {
pub fn new(usd_minimum_per_participation: Balance, usd_maximum_per_did: Option<Balance>) -> Self {
pub const fn new(usd_minimum_per_participation: Balance, usd_maximum_per_did: Option<Balance>) -> Self {
Self { usd_minimum_per_participation, usd_maximum_per_did }
}

pub fn usd_ticket_above_minimum_per_participation(&self, usd_amount: Balance) -> bool {
pub const fn usd_ticket_above_minimum_per_participation(&self, usd_amount: Balance) -> bool {
usd_amount >= self.usd_minimum_per_participation
}

pub fn usd_ticket_below_maximum_per_did(&self, usd_amount: Balance) -> bool {
pub const fn usd_ticket_below_maximum_per_did(&self, usd_amount: Balance) -> bool {
match self.usd_maximum_per_did {
Some(max) => usd_amount <= max,
None => true,
}
}

pub fn check_valid(&self, bound: Bound) -> bool {
pub const fn check_valid(&self, bound: Bound) -> bool {
if let (min, Some(max)) = (self.usd_minimum_per_participation, self.usd_maximum_per_did) {
if min > max {
return false
Expand Down Expand Up @@ -766,7 +766,7 @@ pub mod inner {
Classic(u8),
}
impl ParticipationMode {
pub fn multiplier(&self) -> u8 {
pub const fn multiplier(&self) -> u8 {
match self {
// OTM multiplier is fixed at 5
ParticipationMode::OTM => 5u8,
Expand Down Expand Up @@ -794,7 +794,7 @@ pub mod inner {
Ethereum,
}
impl ParticipantsAccountType {
pub fn junction_is_supported(&self, junction: &Junction) -> bool {
pub const fn junction_is_supported(&self, junction: &Junction) -> bool {
match self {
// This project expects users to submit a 32 byte account, and sign it with SR25519 crypto
ParticipantsAccountType::Polkadot => matches!(junction, Junction::AccountId32 { .. }),
Expand Down
2 changes: 1 addition & 1 deletion pallets/linear-release/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub mod pallet {
#[pallet::extra_constants]
impl<T: Config> Pallet<T> {
#[pallet::constant_name(MaxVestingSchedules)]
fn max_vesting_schedules() -> u32 {
const fn max_vesting_schedules() -> u32 {
T::MAX_VESTING_SCHEDULES
}
}
Expand Down
10 changes: 5 additions & 5 deletions pallets/on-slash-vesting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ use pallet_vesting::Vesting;
use sp_runtime::{traits::BlockNumberProvider, BoundedVec};

pub trait OnSlash<AccountId, Balance: Clone> {
fn on_slash(account: &AccountId, amount: Balance);
fn on_slash(account: &AccountId, amount: &Balance);
}

#[impl_trait_for_tuples::impl_for_tuples(30)]
impl<AccountId, Balance: Clone> OnSlash<AccountId, Balance> for Tuple {
fn on_slash(account: &AccountId, amount: Balance) {
for_tuples!( #( Tuple::on_slash(account, amount.clone()); )* );
fn on_slash(account: &AccountId, amount: &Balance) {
for_tuples!( #( Tuple::on_slash(account, amount); )* );
}
}

Expand All @@ -30,12 +30,12 @@ where
T: pallet_vesting::Config,
T::Currency: Currency<AccountIdOf<T>, Balance = u128>,
{
fn on_slash(account: &AccountIdOf<T>, slashed_amount: u128) {
fn on_slash(account: &AccountIdOf<T>, slashed_amount: &u128) {
if let Some(vesting_schedules) = <Vesting<T>>::get(account) {
let mut new_vesting_schedules = BoundedVec::with_bounded_capacity(vesting_schedules.len());
let now = T::BlockNumberProvider::current_block_number();
for schedule in vesting_schedules {
let total_locked = schedule.locked_at::<T::BlockNumberToBalance>(now).saturating_sub(slashed_amount);
let total_locked = schedule.locked_at::<T::BlockNumberToBalance>(now).saturating_sub(*slashed_amount);
let start_block = T::BlockNumberToBalance::convert(now);
let end_block = schedule.ending_block_as_balance::<T::BlockNumberToBalance>();
let duration = end_block.saturating_sub(start_block);
Expand Down
Loading