diff --git a/pallets/funding/src/functions.rs b/pallets/funding/src/functions.rs index 056d9fc49..7574b5386 100644 --- a/pallets/funding/src/functions.rs +++ b/pallets/funding/src/functions.rs @@ -24,7 +24,8 @@ use frame_support::{ ensure, pallet_prelude::*, traits::{ - fungible::{Mutate, MutateHold as FungibleMutateHold}, + fungible::{ + Mutate, MutateHold as FungibleMutateHold}, fungibles::{ metadata::{Inspect as MetadataInspect, Mutate as MetadataMutate}, Create, Inspect as FungibleInspect, Mutate as FungiblesMutate, diff --git a/pallets/funding/src/mock.rs b/pallets/funding/src/mock.rs index 3226abaea..c7a2d6efb 100644 --- a/pallets/funding/src/mock.rs +++ b/pallets/funding/src/mock.rs @@ -495,7 +495,21 @@ pub fn new_test_ext() -> sp_io::TestExternalities { 10, ), ], - metadata: vec![], + metadata: vec![ + ( + AcceptedFundingAsset::USDT.to_assethub_id(), + "USDT".as_bytes().to_vec(), + "USDT".as_bytes().to_vec(), + 6, + ), + ( + AcceptedFundingAsset::USDC.to_assethub_id(), + "USDC".as_bytes().to_vec(), + "USDC".as_bytes().to_vec(), + 6, + ), + (AcceptedFundingAsset::DOT.to_assethub_id(), "DOT".as_bytes().to_vec(), "DOT".as_bytes().to_vec(), 10), + ], accounts: vec![], }, ..Default::default() diff --git a/pallets/funding/src/tests/3_auction.rs b/pallets/funding/src/tests/3_auction.rs index 1f74028d7..d732bed4d 100644 --- a/pallets/funding/src/tests/3_auction.rs +++ b/pallets/funding/src/tests/3_auction.rs @@ -7,6 +7,7 @@ mod round_flow { #[cfg(test)] mod success { use super::*; + use frame_support::traits::fungibles::metadata::Inspect; use sp_core::bounded_vec; use std::ops::Not; @@ -476,10 +477,12 @@ mod round_flow { let usdt_fundings = accounts .iter() - .map(|acc| UserToForeignAssets { - account: acc.clone(), - asset_amount: USDT_UNIT * 1_000_000, - asset_id: fundings.next().unwrap().to_assethub_id(), + .map(|acc| { + let accepted_asset = fundings.next().unwrap(); + let asset_id = accepted_asset.to_assethub_id(); + let asset_decimals = inst.execute(|| ::FundingCurrency::decimals(asset_id)); + let asset_unit = 10u128.checked_pow(asset_decimals.into()).unwrap(); + UserToForeignAssets { account: acc.clone(), asset_amount: asset_unit * 1_000_000, asset_id } }) .collect_vec(); inst.mint_plmc_to(plmc_fundings); diff --git a/pallets/funding/src/tests/4_community.rs b/pallets/funding/src/tests/4_community.rs index cde9f0286..6a6591b3c 100644 --- a/pallets/funding/src/tests/4_community.rs +++ b/pallets/funding/src/tests/4_community.rs @@ -182,19 +182,23 @@ mod community_contribute_extrinsic { evaluations, default_bids(), ); + let ct_price = inst.get_project_details(project_id).weighted_average_price.unwrap(); + let plmc_price = ::PriceProvider::get_decimals_aware_price( + PLMC_FOREIGN_ID, + USD_DECIMALS, + PLMC_DECIMALS, + ) + .unwrap(); - let evaluation_bond = + let evaluation_plmc_bond = inst.execute(|| Balances::balance_on_hold(&HoldReason::Evaluation(project_id).into(), &BOB)); - let slashable_bond = ::EvaluatorSlash::get() * evaluation_bond; - let usable_bond = evaluation_bond - slashable_bond; + let slashable_plmc = ::EvaluatorSlash::get() * evaluation_plmc_bond; + let usable_plmc = evaluation_plmc_bond - slashable_plmc; - let plmc_price = ::PriceProvider::get_price(PLMC_FOREIGN_ID).unwrap(); - let ct_price = inst.get_project_details(project_id).weighted_average_price.unwrap(); + let usable_usd = plmc_price.checked_mul_int(usable_plmc).unwrap(); + let slashable_usd = plmc_price.checked_mul_int(slashable_plmc).unwrap(); - let usable_usd = plmc_price.saturating_mul_int(usable_bond); let usable_ct = ct_price.reciprocal().unwrap().saturating_mul_int(usable_usd); - - let slashable_usd = plmc_price.saturating_mul_int(slashable_bond); let slashable_ct = ct_price.reciprocal().unwrap().saturating_mul_int(slashable_usd); // Can't contribute with only the evaluation bond @@ -274,10 +278,10 @@ mod community_contribute_extrinsic { let project_id = inst.create_auctioning_project(default_project_metadata(ISSUER_2), ISSUER_2, evaluations); - let evaluation_bond = + let evaluation_plmc_bond = inst.execute(|| Balances::balance_on_hold(&HoldReason::Evaluation(project_id).into(), &bob)); - let slashable_bond = ::EvaluatorSlash::get() * evaluation_bond; - let usable_bond = evaluation_bond - slashable_bond; + let slashable_plmc_bond = ::EvaluatorSlash::get() * evaluation_plmc_bond; + let usable_plmc_bond = evaluation_plmc_bond - slashable_plmc_bond; let bids_plmc = inst.calculate_auction_plmc_charged_from_all_bids_made_or_with_bucket( &all_bids, @@ -306,10 +310,15 @@ mod community_contribute_extrinsic { inst.start_community_funding(project_id).unwrap(); assert_eq!(inst.get_project_details(project_id).status, ProjectStatus::CommunityRound); - let plmc_price = ::PriceProvider::get_price(PLMC_FOREIGN_ID).unwrap(); + let plmc_price = ::PriceProvider::get_decimals_aware_price( + PLMC_FOREIGN_ID, + USD_DECIMALS, + PLMC_DECIMALS, + ) + .unwrap(); let wap = inst.get_project_details(project_id).weighted_average_price.unwrap(); - let usable_usd = plmc_price.saturating_mul_int(usable_bond); + let usable_usd = plmc_price.saturating_mul_int(usable_plmc_bond); let usable_ct = wap.reciprocal().unwrap().saturating_mul_int(usable_usd); let bob_contribution = (bob, 1337 * CT_UNIT).into();