Skip to content

Commit

Permalink
Set balance to u128 instead of config type on pallet_funding
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed Sep 4, 2024
1 parent cb4d134 commit 9fc2c56
Show file tree
Hide file tree
Showing 27 changed files with 315 additions and 455 deletions.
14 changes: 7 additions & 7 deletions integration-tests/penpal/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use super::{
use crate::{BaseDeliveryFee, FeeAssetId, TransactionByteFee};
use core::marker::PhantomData;
use frame_support::{
match_types, parameter_types,
parameter_types,
traits::{ConstU32, Contains, ContainsPair, Everything, EverythingBut, Get, Nothing},
weights::Weight,
};
Expand All @@ -44,12 +44,12 @@ use sp_runtime::traits::{AccountIdConversion, ConvertInto, Identity, TryConvertI
use xcm::latest::prelude::*;
use xcm_builder::{
AccountId32Aliases, AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain,
AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, AsPrefixedGeneralIndex,
ConvertedConcreteId, EnsureXcmOrigin, FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter,
FungiblesAdapter, IsConcrete, LocalMint, NativeAsset, NoChecking, ParentAsSuperuser, ParentIsPreset,
RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,
SignedToAccountId32, SovereignSignedViaLocation, StartsWith, TakeWeightCredit, TrailingSetTopicAsId,
UsingComponents, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, XcmFeeToAccount,
AllowKnownQueryResponses, AllowSubscriptionsFrom, AsPrefixedGeneralIndex, ConvertedConcreteId, EnsureXcmOrigin,
FixedWeightBounds, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, IsConcrete, LocalMint,
NativeAsset, NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative,
SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,
StartsWith, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WithComputedOrigin, WithUniqueTopic,
XcmFeeManagerFromComponents, XcmFeeToAccount,
};
use xcm_executor::{traits::JustTry, XcmExecutor};

Expand Down
4 changes: 2 additions & 2 deletions integration-tests/src/tests/ct_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn create_settled_project() -> (ProjectId, Vec<AccountId>) {
fn full_pallet_migration_test() {
polimec::set_prices();
let (project_id, participants) = create_settled_project();
let project_status =
let _project_status =
PolimecNet::execute_with(|| pallet_funding::ProjectsDetails::<PolimecRuntime>::get(project_id).unwrap().status);

mock_hrmp_establishment(project_id);
Expand Down Expand Up @@ -304,7 +304,7 @@ fn cannot_start_pallet_migration_with_unsettled_participations() {

let tups = vec![tup_1, tup_2, tup_3];

for (project_id, participants) in tups.into_iter() {
for (project_id, _participants) in tups.into_iter() {
PolimecNet::execute_with(|| {
assert_noop!(
PolimecFunding::do_start_pallet_migration(&ISSUER.into(), project_id, ParaId::from(6969u32)),
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/src/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ fn ct_minted() {
let mut inst = IntegrationInstantiator::new(None);

PolimecNet::execute_with(|| {
let project_id = inst.create_settled_project(
let _project_id = inst.create_settled_project(
excel_project(),
ISSUER.into(),
None,
Expand Down Expand Up @@ -511,9 +511,9 @@ fn ct_migrated() {

// Migrate CTs
let accounts = excel_ct_amounts().iter().map(|item| item.0.clone()).unique().collect::<Vec<_>>();
let total_ct_sold = excel_ct_amounts().iter().fold(FixedU128::zero(), |acc, item| acc + item.1);
let _total_ct_sold = excel_ct_amounts().iter().fold(FixedU128::zero(), |acc, item| acc + item.1);
let polimec_sov_acc = PenNet::sovereign_account_id_of((Parent, Parachain(polimec::PARA_ID)).into());
let polimec_fund_balance = PenNet::account_data_of(polimec_sov_acc);
let _polimec_fund_balance = PenNet::account_data_of(polimec_sov_acc);

let names = names();

Expand Down
3 changes: 1 addition & 2 deletions integration-tests/src/tests/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ use frame_support::{
use pallet_democracy::{AccountVote, Conviction, GetElectorate, ReferendumInfo, Vote};
use pallet_vesting::VestingInfo;
use polimec_runtime::{
Balances, Council, Democracy, Elections, ParachainStaking, Preimage, RuntimeOrigin, TechnicalCommittee, Treasury,
Vesting, PLMC,
Balances, Council, Democracy, Elections, ParachainStaking, Preimage, RuntimeOrigin, Treasury, Vesting, PLMC,
};
use xcm_emulator::helpers::get_account_id_from_seed;
generate_accounts!(PEPE, CARLOS,);
Expand Down
111 changes: 26 additions & 85 deletions pallets/funding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,38 +62,21 @@ where
let metadata_hash = BoundedVec::try_from(IPFS_CID.as_bytes().to_vec()).unwrap();
ProjectMetadata {
token_information: CurrencyMetadata { name: bounded_name, symbol: bounded_symbol, decimals: CT_DECIMALS },
mainnet_token_max_supply: BalanceOf::<T>::try_from(1_000_000 * CT_UNIT)
.unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
total_allocation_size: BalanceOf::<T>::try_from(1_000_000 * CT_UNIT)
.unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
mainnet_token_max_supply: 1_000_000u128 * CT_UNIT,
total_allocation_size: 1_000_000u128 * CT_UNIT,
auction_round_allocation_percentage: Percent::from_percent(50u8),
minimum_price: PriceProviderOf::<T>::calculate_decimals_aware_price(10u128.into(), USD_DECIMALS, CT_DECIMALS)
.unwrap(),

bidding_ticket_sizes: BiddingTicketSizes {
professional: TicketSize::new(
BalanceOf::<T>::try_from(5000 * USD_UNIT).unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
None,
),
institutional: TicketSize::new(
BalanceOf::<T>::try_from(5000 * USD_UNIT).unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
None,
),
professional: TicketSize::new(5000u128 * USD_UNIT, None),
institutional: TicketSize::new(5000u128 * USD_UNIT, None),
phantom: Default::default(),
},
contributing_ticket_sizes: ContributingTicketSizes {
retail: TicketSize::new(
BalanceOf::<T>::try_from(USD_UNIT).unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
None,
),
professional: TicketSize::new(
BalanceOf::<T>::try_from(USD_UNIT).unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
None,
),
institutional: TicketSize::new(
BalanceOf::<T>::try_from(USD_UNIT).unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
None,
),
retail: TicketSize::new(USD_UNIT, None),
professional: TicketSize::new(USD_UNIT, None),
institutional: TicketSize::new(USD_UNIT, None),
phantom: Default::default(),
},
participation_currencies: vec![AcceptedFundingAsset::USDT].try_into().unwrap(),
Expand All @@ -105,7 +88,6 @@ where
pub fn default_evaluations<T: Config>() -> Vec<UserToUSDBalance<T>>
where
<T as Config>::Price: From<u128>,
<T as Config>::Balance: From<u128>,
T::Hash: From<H256>,
{
let threshold = <T as Config>::EvaluationSuccessThreshold::get();
Expand Down Expand Up @@ -134,7 +116,6 @@ where
pub fn default_bids<T: Config>() -> Vec<BidParams<T>>
where
<T as Config>::Price: From<u128>,
<T as Config>::Balance: From<u128>,
T::Hash: From<H256>,
{
let default_project_metadata = default_project_metadata::<T>(account::<AccountIdOf<T>>("issuer", 0, 0));
Expand All @@ -156,7 +137,6 @@ pub fn full_bids<T>() -> Vec<BidParams<T>>
where
T: Config,
<T as Config>::Price: From<u128>,
<T as Config>::Balance: From<u128>,
T::Hash: From<H256>,
{
let inst = BenchInstantiator::<T>::new(None);
Expand All @@ -175,7 +155,6 @@ where
pub fn default_community_contributions<T: Config>() -> Vec<ContributionParams<T>>
where
<T as Config>::Price: From<u128>,
<T as Config>::Balance: From<u128>,
T::Hash: From<H256>,
{
let inst = BenchInstantiator::<T>::new(None);
Expand All @@ -201,7 +180,6 @@ where
pub fn default_remainder_contributions<T: Config>() -> Vec<ContributionParams<T>>
where
<T as Config>::Price: From<u128>,
<T as Config>::Balance: From<u128>,
T::Hash: From<H256>,
{
let inst = BenchInstantiator::<T>::new(None);
Expand Down Expand Up @@ -289,13 +267,12 @@ pub fn string_account<AccountId: Decode>(

#[benchmarks(
where
T: Config + frame_system::Config<RuntimeEvent = <T as Config>::RuntimeEvent> + pallet_balances::Config<Balance = BalanceOf<T>> + sp_std::fmt::Debug,
T: Config + frame_system::Config<RuntimeEvent = <T as Config>::RuntimeEvent> + pallet_balances::Config<Balance = Balance> + sp_std::fmt::Debug,
<T as Config>::RuntimeEvent: TryInto<Event<T>> + Parameter + Member,
<T as Config>::Price: From<u128>,
<T as Config>::Balance: From<u128> + Into<u128>,
T::Hash: From<H256>,
<T as frame_system::Config>::AccountId: Into<<<T as frame_system::Config>::RuntimeOrigin as OriginTrait>::AccountId> + sp_std::fmt::Debug,
<T as pallet_balances::Config>::Balance: Into<BalanceOf<T>>,
<T as pallet_balances::Config>::Balance: Into<Balance>,
)]
mod benchmarks {
use super::*;
Expand Down Expand Up @@ -327,7 +304,7 @@ mod benchmarks {
let ct_treasury_account_deposit = T::ContributionTokenCurrency::deposit_required(0);
inst.mint_plmc_to(vec![UserToPLMCBalance::new(
issuer.clone(),
ed * 2u64.into() + metadata_deposit + ct_treasury_account_deposit,
ed * 2u128 + metadata_deposit + ct_treasury_account_deposit,
)]);
let jwt = get_mock_jwt_with_cid(
issuer.clone(),
Expand Down Expand Up @@ -411,10 +388,8 @@ mod benchmarks {
symbol: BoundedVec::try_from("CTESTv2".as_bytes().to_vec()).unwrap(),
decimals: CT_DECIMALS - 2,
},
mainnet_token_max_supply: BalanceOf::<T>::try_from(200_000 * CT_UNIT)
.unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
total_allocation_size: BalanceOf::<T>::try_from(200_000 * CT_UNIT)
.unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
mainnet_token_max_supply: 200_000u128 * CT_UNIT,
total_allocation_size: 200_000u128 * CT_UNIT,
auction_round_allocation_percentage: Percent::from_percent(30u8),
minimum_price: PriceProviderOf::<T>::calculate_decimals_aware_price(
11u128.into(),
Expand All @@ -423,44 +398,14 @@ mod benchmarks {
)
.unwrap(),
bidding_ticket_sizes: BiddingTicketSizes {
professional: TicketSize::new(
BalanceOf::<T>::try_from(5000 * USD_UNIT).unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
Some(
BalanceOf::<T>::try_from(10_000 * USD_UNIT)
.unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
),
),
institutional: TicketSize::new(
BalanceOf::<T>::try_from(5000 * USD_UNIT).unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
Some(
BalanceOf::<T>::try_from(10_000 * USD_UNIT)
.unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
),
),
professional: TicketSize::new(5000 * USD_UNIT, Some(10_000 * USD_UNIT)),
institutional: TicketSize::new(5000 * USD_UNIT, Some(10_000 * USD_UNIT)),
phantom: Default::default(),
},
contributing_ticket_sizes: ContributingTicketSizes {
retail: TicketSize::new(
BalanceOf::<T>::try_from(5000 * USD_UNIT).unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
Some(
BalanceOf::<T>::try_from(10_000 * USD_UNIT)
.unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
),
),
professional: TicketSize::new(
BalanceOf::<T>::try_from(5000 * USD_UNIT).unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
Some(
BalanceOf::<T>::try_from(10_000 * USD_UNIT)
.unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
),
),
institutional: TicketSize::new(
BalanceOf::<T>::try_from(5000 * USD_UNIT).unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
Some(
BalanceOf::<T>::try_from(10_000 * USD_UNIT)
.unwrap_or_else(|_| panic!("Failed to create BalanceOf")),
),
),
retail: TicketSize::new(5000 * USD_UNIT, Some(10_000 * USD_UNIT)),
professional: TicketSize::new(5000 * USD_UNIT, Some(10_000 * USD_UNIT)),
institutional: TicketSize::new(5000 * USD_UNIT, Some(10_000 * USD_UNIT)),
phantom: Default::default(),
},
participation_currencies: vec![AcceptedFundingAsset::USDT, AcceptedFundingAsset::USDC].try_into().unwrap(),
Expand Down Expand Up @@ -518,9 +463,9 @@ mod benchmarks {
// Storage
let stored_details = ProjectsDetails::<T>::get(project_id).unwrap();
assert_eq!(stored_details.status, ProjectStatus::EvaluationRound);
let starting_evaluation_info = EvaluationRoundInfoOf::<T> {
total_bonded_usd: Zero::zero(),
total_bonded_plmc: Zero::zero(),
let starting_evaluation_info = EvaluationRoundInfo {
total_bonded_usd: Balance::zero(),
total_bonded_plmc: Balance::zero(),
evaluators_outcome: None,
};
assert_eq!(stored_details.evaluation_round_info, starting_evaluation_info);
Expand Down Expand Up @@ -706,10 +651,8 @@ mod benchmarks {
whitelist_account!(bidder);

let mut project_metadata = default_project_metadata::<T>(issuer.clone());
project_metadata.mainnet_token_max_supply =
(100_000 * CT_UNIT).try_into().unwrap_or_else(|_| panic!("Failed to create BalanceOf"));
project_metadata.total_allocation_size =
(100_000 * CT_UNIT).try_into().unwrap_or_else(|_| panic!("Failed to create BalanceOf"));
project_metadata.mainnet_token_max_supply = 100_000 * CT_UNIT;
project_metadata.total_allocation_size = 100_000 * CT_UNIT;
project_metadata.minimum_price = PriceProviderOf::<T>::calculate_decimals_aware_price(
PriceOf::<T>::checked_from_rational(100, 1).unwrap(),
USD_DECIMALS,
Expand Down Expand Up @@ -790,7 +733,7 @@ mod benchmarks {
let auction_allocation =
project_metadata.auction_round_allocation_percentage * project_metadata.total_allocation_size;
let bucket_size = Percent::from_percent(10) * auction_allocation;
ct_amount = bucket_size * (y as u128).into();
ct_amount = bucket_size * (y as u128);
usdt_for_filler_bidder = usdt_for_new_bidder;
}
let extrinsic_bid = BidParams::new(bidder.clone(), ct_amount, 1u8, AcceptedFundingAsset::USDT);
Expand Down Expand Up @@ -949,10 +892,8 @@ mod benchmarks {
whitelist_account!(issuer);

let mut project_metadata = default_project_metadata::<T>(issuer.clone());
project_metadata.mainnet_token_max_supply =
BalanceOf::<T>::try_from(10_000_000 * CT_UNIT).unwrap_or_else(|_| panic!("Failed to create BalanceOf"));
project_metadata.total_allocation_size =
BalanceOf::<T>::try_from(10_000_000 * CT_UNIT).unwrap_or_else(|_| panic!("Failed to create BalanceOf"));
project_metadata.mainnet_token_max_supply = 10_000_000 * CT_UNIT;
project_metadata.total_allocation_size = 10_000_000 * CT_UNIT;
project_metadata.auction_round_allocation_percentage = Percent::from_percent(100u8);

let project_id = inst.create_auctioning_project(
Expand Down Expand Up @@ -990,7 +931,7 @@ mod benchmarks {
// This one needs to fill the remaining with the bucket, so that all "accepted" bids will take the CT from a rejected one
let last_rejected_bid = BidParams::<T>::new(
account::<AccountIdOf<T>>("bidder", 0, 420),
auction_allocation - (min_bid_amount * CT_UNIT * (y as u128 - 1u128)).into(),
auction_allocation - (min_bid_amount * CT_UNIT * (y as u128 - 1u128)),
1u8,
AcceptedFundingAsset::USDT,
);
Expand Down
4 changes: 2 additions & 2 deletions pallets/funding/src/functions/1_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ impl<T: Config> Pallet<T> {
status: ProjectStatus::Application,
round_duration: BlockNumberPair::new(None, None),
remaining_contribution_tokens: project_metadata.total_allocation_size,
funding_amount_reached_usd: BalanceOf::<T>::zero(),
evaluation_round_info: EvaluationRoundInfoOf::<T> {
funding_amount_reached_usd: Balance::zero(),
evaluation_round_info: EvaluationRoundInfo {
total_bonded_usd: Zero::zero(),
total_bonded_plmc: Zero::zero(),
evaluators_outcome: None,
Expand Down
4 changes: 2 additions & 2 deletions pallets/funding/src/functions/2_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<T: Config> Pallet<T> {
pub fn do_evaluate(
evaluator: &AccountIdOf<T>,
project_id: ProjectId,
usd_amount: BalanceOf<T>,
usd_amount: Balance,
did: Did,
whitelisted_policy: Cid,
) -> DispatchResultWithPostInfo {
Expand Down Expand Up @@ -157,7 +157,7 @@ impl<T: Config> Pallet<T> {
remaining_bond_to_reach_threshold
};

let late_usd_amount = usd_amount.checked_sub(&early_usd_amount).ok_or(Error::<T>::BadMath)?;
let late_usd_amount = usd_amount.checked_sub(early_usd_amount).ok_or(Error::<T>::BadMath)?;

let new_evaluation = EvaluationInfoOf::<T> {
id: evaluation_id,
Expand Down
Loading

0 comments on commit 9fc2c56

Please sign in to comment.