Skip to content

Commit

Permalink
otm_funding_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed Sep 24, 2024
1 parent a04bf46 commit 03aec7c
Show file tree
Hide file tree
Showing 29 changed files with 1,100 additions and 455 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
20 changes: 11 additions & 9 deletions integration-tests/src/tests/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ 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};

Expand Down Expand Up @@ -54,11 +54,13 @@ 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> {
use ParticipationMode::{Classic, OTM};
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> {
use ParticipationMode::{Classic, OTM};
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 +115,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 +136,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 +159,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
26 changes: 13 additions & 13 deletions nodes/parachain/src/chain_spec/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ use frame_support::traits::fungible::Inspect;
use itertools::Itertools;
#[cfg(not(feature = "runtime-benchmarks"))]
use polimec_runtime::MinCandidateStk;
use polimec_runtime::{
pallet_parachain_staking,
pallet_parachain_staking::{
inflation::{perbill_annual_to_perbill_round, BLOCKS_PER_YEAR},
InflationInfo, Range,
},
AccountId, AuraId as AuthorityId, Balance, OracleProvidersMembershipConfig, Runtime, PLMC,
};
use polimec_runtime::{pallet_parachain_staking, pallet_parachain_staking::{
inflation::{perbill_annual_to_perbill_round, BLOCKS_PER_YEAR},
InflationInfo, Range,
}, AccountId, AuraId as AuthorityId, Balance, ContributionTreasuryAccount, ExistentialDeposit, OracleProvidersMembershipConfig, Runtime, TreasuryAccount, PLMC};
use sp_core::{crypto::UncheckedInto, sr25519};
use sp_runtime::{traits::AccountIdConversion, Perbill, Percent};
use polimec_runtime::{BlockchainOperationTreasury, FeeRecipient};

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

/// The default XCM version to set in genesis config.
Expand Down Expand Up @@ -86,13 +84,15 @@ 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
83 changes: 59 additions & 24 deletions pallets/funding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ where
default_project_metadata.minimum_price,
default_weights(),
default_bidders::<T>(),
default_bidder_multipliers(),
default_bidder_modes(),
)
}

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

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

Expand Down Expand Up @@ -241,14 +241,17 @@ 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> {
use ParticipationMode::{Classic, OTM};
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> {
use ParticipationMode::{Classic, OTM};
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> {
use ParticipationMode::{Classic, OTM};
vec![Classic(1u8), OTM, Classic(1u8), OTM, Classic(1u8)]
}

/// Grab an account, seeded by a name and index.
Expand Down Expand Up @@ -665,7 +668,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 +716,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 +746,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 +800,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 +817,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 +876,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 +931,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 +943,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 +953,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 +968,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 +1515,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 +1864,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 +1962,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
20 changes: 10 additions & 10 deletions pallets/funding/src/functions/6_settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use frame_support::{
dispatch::DispatchResult,
ensure,
traits::{
fungible::MutateHold as FungibleMutateHold,
fungible::{Inspect, MutateHold as FungibleMutateHold},
fungibles::Mutate as FungiblesMutate,
tokens::{Fortitude, Precision, Preservation, Restriction},
Get,
Expand Down Expand Up @@ -173,13 +173,14 @@ impl<T: Config> Pallet<T> {
Self::calculate_refund(&bid, funding_success, wap)?;

if bid.mode == ParticipationMode::OTM {
<pallet_proxy_bonding::Pallet<T>>::refund_fee(
project_id,
HoldReason::Participation.into(),
&bid.bidder,
refunded_plmc,
bid.funding_asset.id(),
)?;
if refunded_plmc > T::NativeCurrency::minimum_balance() {
<pallet_proxy_bonding::Pallet<T>>::refund_fee(
project_id,
&bid.bidder,
refunded_plmc,
bid.funding_asset.id(),
)?;
}
} else {
Self::release_participation_bond_for(&bid.bidder, refunded_plmc)?;
}
Expand All @@ -188,7 +189,7 @@ impl<T: Config> Pallet<T> {
if funding_success && bid.status != BidStatus::Rejected {
let ct_vesting_duration = Self::set_plmc_bond_release_with_mode(
bid.bidder.clone(),
bid.plmc_bond,
bid.plmc_bond.saturating_sub(refunded_plmc),
bid.mode,
project_details.funding_end_block.ok_or(Error::<T>::ImpossibleState)?,
)?;
Expand Down Expand Up @@ -267,7 +268,6 @@ impl<T: Config> Pallet<T> {
if contribution.mode == ParticipationMode::OTM {
<pallet_proxy_bonding::Pallet<T>>::refund_fee(
project_id,
HoldReason::Participation.into(),
&contribution.contributor,
contribution.plmc_bond,
contribution.funding_asset.id(),
Expand Down
Loading

0 comments on commit 03aec7c

Please sign in to comment.