Skip to content

Commit

Permalink
otm_funding_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed Oct 3, 2024
1 parent 70e3fed commit 82c42ae
Show file tree
Hide file tree
Showing 30 changed files with 1,092 additions and 447 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions integration-tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ pub mod polimec {
let dot = (AcceptedFundingAsset::DOT.id(), prices.dot);
let usdc = (AcceptedFundingAsset::USDC.id(), prices.usdc);
let usdt = (AcceptedFundingAsset::USDT.id(), prices.usdt);
let plmc = (pallet_funding::PLMC_FOREIGN_ID, prices.plmc);
let plmc = (polimec_common::PLMC_FOREIGN_ID, prices.plmc);

let values: BoundedVec<(u32, FixedU128), <PolimecRuntime as orml_oracle::Config>::MaxFeedValues> =
vec![dot, usdc, usdt, plmc].try_into().expect("benchmarks can panic");
Expand Down Expand Up @@ -501,8 +501,10 @@ pub mod polimec {

funded_accounts.extend(accounts::init_balances().iter().cloned().map(|k| (k, INITIAL_DEPOSIT)));
funded_accounts.extend(collators::initial_authorities().iter().cloned().map(|(acc, _)| (acc, 20_005 * PLMC)));
funded_accounts.push((TreasuryAccount::get(), 20_005 * PLMC));
funded_accounts.push((TreasuryAccount::get(), 20_000_000 * PLMC));
funded_accounts.push((BlockchainOperationTreasury::get(), 20_005 * PLMC));
/// Treasury account needs PLMC for the One Token Model participations
funded_accounts.push((polimec_runtime::FeeRecipient::get(), INITIAL_DEPOSIT));

let genesis_config = polimec_runtime::RuntimeGenesisConfig {
system: Default::default(),
Expand Down
1 change: 1 addition & 0 deletions integration-tests/src/tests/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use sp_runtime::{
AccountId32, DispatchError,
};
use tests::defaults::*;
use ParticipationMode::{Classic, OTM};

#[test]
fn test_jwt_for_create() {
Expand Down
19 changes: 10 additions & 9 deletions integration-tests/src/tests/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ use crate::PolimecRuntime;
use frame_support::BoundedVec;
pub use pallet_funding::instantiator::{BidParams, ContributionParams, UserToUSDBalance};
use pallet_funding::{
AcceptedFundingAsset, BiddingTicketSizes, ContributingTicketSizes, CurrencyMetadata, PriceProviderOf,
ProjectMetadata, ProjectMetadataOf, TicketSize,
AcceptedFundingAsset, BiddingTicketSizes, ContributingTicketSizes, CurrencyMetadata, ParticipationMode,
PriceProviderOf, ProjectMetadata, ProjectMetadataOf, TicketSize,
};
use sp_arithmetic::{FixedPointNumber, Percent};

use macros::generate_accounts;
use polimec_common::{ProvideAssetPrice, USD_DECIMALS, USD_UNIT};
use polimec_runtime::{AccountId, PLMC};
use sp_runtime::{traits::ConstU32, Perquintill};
use ParticipationMode::{Classic, OTM};

pub const IPFS_CID: &str = "QmeuJ24ffwLAZppQcgcggJs3n689bewednYkuc8Bx5Gngz";
pub const CT_DECIMALS: u8 = 18;
Expand Down Expand Up @@ -54,11 +55,11 @@ pub fn ipfs_hash() -> BoundedVec<u8, ConstU32<96>> {
pub fn default_weights() -> Vec<u8> {
vec![20u8, 15u8, 10u8, 25u8, 30u8]
}
pub fn default_bidder_multipliers() -> Vec<u8> {
vec![1u8, 6u8, 10u8, 8u8, 3u8]
pub fn default_bidder_modes() -> Vec<ParticipationMode> {
vec![Classic(1u8), Classic(6u8), OTM, OTM, Classic(3u8)]
}
pub fn default_contributor_multipliers() -> Vec<u8> {
vec![1u8, 1u8, 1u8, 1u8, 1u8]
pub fn default_contributor_modes() -> Vec<ParticipationMode> {
vec![Classic(1u8), Classic(1u8), OTM, OTM, Classic(3u8)]
}

pub fn default_project_metadata(issuer: AccountId) -> ProjectMetadataOf<polimec_runtime::Runtime> {
Expand Down Expand Up @@ -113,7 +114,7 @@ pub fn default_bids() -> Vec<BidParams<PolimecRuntime>> {
default_metadata.minimum_price,
default_weights(),
default_bidders(),
default_bidder_multipliers(),
default_bidder_modes(),
)
}

Expand All @@ -134,7 +135,7 @@ pub fn default_community_contributions() -> Vec<ContributionParams<PolimecRuntim
default_metadata.minimum_price,
default_weights(),
default_community_contributors(),
default_contributor_multipliers(),
default_contributor_modes(),
)
}

Expand All @@ -157,7 +158,7 @@ pub fn default_remainder_contributions() -> Vec<ContributionParams<PolimecRuntim
default_metadata.minimum_price,
vec![20u8, 15u8, 10u8, 25u8, 23u8, 7u8],
default_remainder_contributors(),
vec![1u8, 1u8, 1u8, 1u8, 1u8, 1u8],
default_contributor_modes(),
)
}
pub fn default_community_contributors() -> Vec<AccountId> {
Expand Down
15 changes: 9 additions & 6 deletions nodes/parachain/src/chain_spec/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ use polimec_runtime::{
inflation::{perbill_annual_to_perbill_round, BLOCKS_PER_YEAR},
InflationInfo, Range,
},
AccountId, AuraId as AuthorityId, Balance, OracleProvidersMembershipConfig, Runtime, PLMC,
AccountId, AuraId as AuthorityId, Balance, BlockchainOperationTreasury, ContributionTreasuryAccount,
ExistentialDeposit, FeeRecipient, OracleProvidersMembershipConfig, Runtime, TreasuryAccount, PLMC,
};
use sp_core::{crypto::UncheckedInto, sr25519};
use sp_runtime::{traits::AccountIdConversion, Perbill, Percent};

pub type ChainSpec = sc_service::GenericChainSpec<Extensions>;

/// The default XCM version to set in genesis config.
Expand Down Expand Up @@ -86,13 +88,14 @@ pub fn genesis_config(genesis_config_params: GenesisConfigParams) -> serde_json:
id,
} = genesis_config_params;

let ed = ExistentialDeposit::get();
let system_accounts = vec![
(
<Runtime as pallet_funding::Config>::ContributionTreasury::get(),
<Runtime as pallet_funding::Config>::NativeCurrency::minimum_balance(),
),
(ContributionTreasuryAccount::get(), ed),
(FeeRecipient::get(), ed),
// Need this to have enough for staking rewards
(<Runtime as pallet_parachain_staking::Config>::PayMaster::get(), 10_000_000 * PLMC),
(BlockchainOperationTreasury::get(), 10_000_000 * PLMC),
// Need this to have enough for proxy bonding
(TreasuryAccount::get(), 10_000_000 * PLMC),
];
endowed_accounts.append(&mut system_accounts.clone());

Expand Down
82 changes: 58 additions & 24 deletions pallets/funding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

use super::*;
use crate::{instantiator::*, traits::SetPrices};
use ParticipationMode::{Classic, OTM};

use frame_benchmarking::v2::*;
use frame_support::{
assert_ok,
Expand Down Expand Up @@ -126,7 +128,7 @@ where
default_project_metadata.minimum_price,
default_weights(),
default_bidders::<T>(),
default_bidder_multipliers(),
default_bidder_modes(),
)
}

Expand All @@ -145,7 +147,7 @@ where
default_project.minimum_price,
default_weights(),
default_bidders::<T>(),
default_bidder_multipliers(),
default_bidder_modes(),
)
}

Expand All @@ -170,7 +172,7 @@ where
default_project_metadata.minimum_price,
default_weights(),
default_community_contributors::<T>(),
default_community_contributor_multipliers(),
default_community_contributor_modes(),
)
}

Expand All @@ -195,7 +197,7 @@ where
10u128.into(),
default_weights(),
default_remainder_contributors::<T>(),
default_remainder_contributor_multipliers(),
default_remainder_contributor_modes(),
)
}

Expand Down Expand Up @@ -241,14 +243,14 @@ pub fn default_remainder_contributors<T: Config>() -> Vec<AccountIdOf<T>> {
]
}

pub fn default_bidder_multipliers() -> Vec<u8> {
vec![10u8, 3u8, 1u8, 7u8, 4u8]
pub fn default_bidder_modes() -> Vec<ParticipationMode> {
vec![Classic(10u8), Classic(3u8), OTM, OTM, Classic(4u8)]
}
pub fn default_community_contributor_multipliers() -> Vec<u8> {
vec![2u8, 1u8, 3u8, 1u8, 1u8]
pub fn default_community_contributor_modes() -> Vec<ParticipationMode> {
vec![Classic(2u8), Classic(1u8), Classic(3u8), OTM, OTM]
}
pub fn default_remainder_contributor_multipliers() -> Vec<u8> {
vec![1u8, 11u8, 1u8, 1u8, 1u8]
pub fn default_remainder_contributor_modes() -> Vec<ParticipationMode> {
vec![Classic(1u8), OTM, Classic(1u8), OTM, Classic(1u8)]
}

/// Grab an account, seeded by a name and index.
Expand Down Expand Up @@ -665,7 +667,12 @@ mod benchmarks {

let project_id = inst.create_auctioning_project(project_metadata.clone(), issuer, None, evaluations);

let existing_bid = BidParams::new(bidder.clone(), (50 * CT_UNIT).into(), 5u8, AcceptedFundingAsset::USDT);
let existing_bid = BidParams::new(
bidder.clone(),
(50 * CT_UNIT).into(),
ParticipationMode::Classic(5u8),
AcceptedFundingAsset::USDT,
);

let existing_bids = vec![existing_bid; x as usize];
let existing_bids_post_bucketing =
Expand Down Expand Up @@ -708,7 +715,12 @@ mod benchmarks {
let current_bucket = Buckets::<T>::get(project_id).unwrap();
// first lets bring the bucket to almost its limit with another bidder:
assert!(new_bidder.clone() != bidder.clone());
let bid_params = BidParams::new(new_bidder, current_bucket.amount_left, 1u8, AcceptedFundingAsset::USDT);
let bid_params = BidParams::new(
new_bidder,
current_bucket.amount_left,
ParticipationMode::Classic(1u8),
AcceptedFundingAsset::USDT,
);
maybe_filler_bid = Some(bid_params.clone());
let plmc_for_new_bidder = inst.calculate_auction_plmc_charged_with_given_price(
&vec![bid_params.clone()],
Expand All @@ -733,7 +745,8 @@ mod benchmarks {
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);
let extrinsic_bid =
BidParams::new(bidder.clone(), ct_amount, ParticipationMode::Classic(1u8), AcceptedFundingAsset::USDT);
let original_extrinsic_bid = extrinsic_bid.clone();
let current_bucket = Buckets::<T>::get(project_id).unwrap();
// we need to call this after bidding `x` amount of times, to get the latest bucket from storage
Expand Down Expand Up @@ -786,7 +799,7 @@ mod benchmarks {
jwt,
project_id,
original_extrinsic_bid.amount,
original_extrinsic_bid.multiplier,
original_extrinsic_bid.mode,
original_extrinsic_bid.asset,
);

Expand All @@ -803,7 +816,7 @@ mod benchmarks {
original_ct_usd_price: Some(price),
funding_asset: Some(AcceptedFundingAsset::USDT),
funding_asset_amount_locked: None,
multiplier: Some(bid_params.multiplier),
mode: Some(bid_params.mode),
plmc_bond: None,
when: None,
};
Expand Down Expand Up @@ -862,11 +875,11 @@ mod benchmarks {
Event::<T>::Bid {
project_id,
ct_amount,
multiplier, ..
mode, ..
},
project_id == project_id,
ct_amount == bid_params.amount,
multiplier == bid_params.multiplier
mode == bid_params.mode
};
assert!(maybe_event.is_some(), "Event not found");
}
Expand Down Expand Up @@ -917,7 +930,7 @@ mod benchmarks {
BidParams::<T>::new(
account::<AccountIdOf<T>>("bidder", 0, i),
(min_bid_amount * CT_UNIT).into(),
1u8,
ParticipationMode::Classic(1u8),
AcceptedFundingAsset::USDT,
)
})
Expand All @@ -929,7 +942,7 @@ mod benchmarks {
let last_rejected_bid = BidParams::<T>::new(
account::<AccountIdOf<T>>("bidder", 0, 420),
auction_allocation - (min_bid_amount * CT_UNIT * (y as u128 - 1u128)),
1u8,
ParticipationMode::Classic(1u8),
AcceptedFundingAsset::USDT,
);
all_bids.push(last_rejected_bid.clone());
Expand All @@ -939,7 +952,7 @@ mod benchmarks {
let allocation_bid = BidParams::<T>::new(
account::<AccountIdOf<T>>("bidder", 0, y),
auction_allocation,
1u8,
ParticipationMode::Classic(1u8),
AcceptedFundingAsset::USDT,
);
all_bids.push(allocation_bid);
Expand All @@ -954,7 +967,7 @@ mod benchmarks {
BidParams::<T>::new(
account::<AccountIdOf<T>>("bidder", 0, i),
(min_bid_amount * CT_UNIT).into(),
1u8,
ParticipationMode::Classic(1u8),
AcceptedFundingAsset::USDT,
)
})
Expand Down Expand Up @@ -1501,7 +1514,14 @@ mod benchmarks {
.map(|_| UserToUSDBalance::new(participant.clone(), (100 * USD_UNIT).into()))
.collect_vec();
let participant_bids = (0..max_bids)
.map(|_| BidParams::new(participant.clone(), (500 * CT_UNIT).into(), 1u8, AcceptedFundingAsset::USDT))
.map(|_| {
BidParams::new(
participant.clone(),
(500 * CT_UNIT).into(),
ParticipationMode::Classic(1u8),
AcceptedFundingAsset::USDT,
)
})
.collect_vec();
let participant_contributions = (0..max_contributions)
.map(|_| {
Expand Down Expand Up @@ -1843,7 +1863,14 @@ mod benchmarks {
.map(|_| UserToUSDBalance::new(participant.clone(), (100 * USD_UNIT).into()))
.collect_vec();
let participant_bids = (0..max_bids)
.map(|_| BidParams::new(participant.clone(), (500 * CT_UNIT).into(), 1u8, AcceptedFundingAsset::USDT))
.map(|_| {
BidParams::new(
participant.clone(),
(500 * CT_UNIT).into(),
ParticipationMode::Classic(1u8),
AcceptedFundingAsset::USDT,
)
})
.collect_vec();
let participant_contributions = (0..max_contributions)
.map(|_| {
Expand Down Expand Up @@ -1934,7 +1961,14 @@ mod benchmarks {
.map(|_| UserToUSDBalance::new(participant.clone(), (100 * USD_UNIT).into()))
.collect_vec();
let participant_bids = (0..max_bids)
.map(|_| BidParams::new(participant.clone(), (500 * CT_UNIT).into(), 1u8, AcceptedFundingAsset::USDT))
.map(|_| {
BidParams::new(
participant.clone(),
(500 * CT_UNIT).into(),
ParticipationMode::Classic(1u8),
AcceptedFundingAsset::USDT,
)
})
.collect_vec();
let participant_contributions = (0..max_contributions)
.map(|_| {
Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/functions/4_contribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<T: Config> Pallet<T> {
contributor: contributor.clone(),
ct_amount: buyable_tokens,
usd_contribution_amount: ticket_size,
mode: mode.clone(),
mode,
funding_asset,
funding_asset_amount,
plmc_bond,
Expand Down
Loading

0 comments on commit 82c42ae

Please sign in to comment.