Skip to content

Commit

Permalink
Funding Rounds Simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios authored and lrazovic committed Feb 3, 2025
1 parent a37d455 commit d2317e5
Show file tree
Hide file tree
Showing 43 changed files with 1,150 additions and 6,472 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,4 @@ cumulus-pallet-session-benchmarking = { version = "16.0.0", default-features = f
# Runtimes
polimec-runtime = { path = "runtimes/polimec" }
rococo-runtime-constants = { version = "14.0.0" }
rococo-runtime = { version = "14.0.0" }
rococo-runtime = { version = "14.0.0" }
4 changes: 2 additions & 2 deletions integration-tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,13 @@ pub mod polimec {
(dot_asset_id.clone(), alice_account.clone(), true, 100_000_000),
(usdt_asset_id.clone(), alice_account.clone(), true, 70_000),
(usdc_asset_id.clone(), alice_account.clone(), true, 70_000),
(weth_asset_id, alice_account.clone(), true, 0_000_041_000_000_000_000),
(weth_asset_id.clone(), alice_account.clone(), true, 0_000_041_000_000_000_000),
],
metadata: vec![
(dot_asset_id, "Local DOT".as_bytes().to_vec(), "DOT".as_bytes().to_vec(), 10),
(usdt_asset_id, "Local USDT".as_bytes().to_vec(), "USDT".as_bytes().to_vec(), 6),
(usdc_asset_id.clone(), "Local USDC".as_bytes().to_vec(), "USDC".as_bytes().to_vec(), 6),
(usdc_asset_id, "Local WETH".as_bytes().to_vec(), "WETH".as_bytes().to_vec(), 18),
(weth_asset_id, "Local WETH".as_bytes().to_vec(), "WETH".as_bytes().to_vec(), 18),
],
accounts: vec![],
},
Expand Down
52 changes: 10 additions & 42 deletions integration-tests/src/tests/ct_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,12 @@ fn migrations_are_vested(project_id: u32, accounts: Vec<AccountId>) {

fn create_settled_project() -> (ProjectId, Vec<AccountId>) {
let mut inst = IntegrationInstantiator::new(None);

let project_metadata = default_project_metadata(ISSUER.into());
let evaluations = inst.generate_successful_evaluations(project_metadata.clone(), 5);
let bids = inst.generate_bids_from_total_ct_percent(project_metadata.clone(), 95, 8);
PolimecNet::execute_with(|| {
let project_id = inst.create_finished_project(
default_project_metadata(ISSUER.into()),
ISSUER.into(),
None,
default_evaluations(),
default_bids(),
default_community_contributions(),
default_remainder_contributions(),
);
let project_id = inst.create_finished_project(project_metadata, ISSUER.into(), None, evaluations, bids);
assert_eq!(
inst.go_to_next_state(project_id),
pallet_funding::ProjectStatus::SettlementStarted(FundingOutcome::Success)
Expand Down Expand Up @@ -214,15 +210,10 @@ fn full_pallet_migration_test() {
fn create_project_with_unsettled_participation(participation_type: ParticipationType) -> (ProjectId, Vec<AccountId>) {
let mut inst = IntegrationInstantiator::new(None);
PolimecNet::execute_with(|| {
let project_id = inst.create_finished_project(
default_project_metadata(ISSUER.into()),
ISSUER.into(),
None,
default_evaluations(),
default_bids(),
default_community_contributions(),
default_remainder_contributions(),
);
let project_metadata = default_project_metadata(ISSUER.into());
let evaluations = inst.generate_successful_evaluations(project_metadata.clone(), 5);
let bids = inst.generate_bids_from_total_ct_percent(project_metadata.clone(), 95, 8);
let project_id = inst.create_finished_project(project_metadata, ISSUER.into(), None, evaluations, bids);

assert_eq!(
inst.go_to_next_state(project_id),
Expand All @@ -231,14 +222,11 @@ fn create_project_with_unsettled_participation(participation_type: Participation
let evaluations_to_settle =
pallet_funding::Evaluations::<PolimecRuntime>::iter_prefix_values((project_id,)).collect_vec();
let bids_to_settle = pallet_funding::Bids::<PolimecRuntime>::iter_prefix_values((project_id,)).collect_vec();
let contributions_to_settle =
pallet_funding::Contributions::<PolimecRuntime>::iter_prefix_values((project_id,)).collect_vec();

let mut participants: Vec<AccountId> = evaluations_to_settle
.iter()
.map(|eval| eval.evaluator.clone())
.chain(bids_to_settle.iter().map(|bid| bid.bidder.clone()))
.chain(contributions_to_settle.iter().map(|contribution| contribution.contributor.clone()))
.collect();
participants.sort();
participants.dedup();
Expand All @@ -259,35 +247,16 @@ fn create_project_with_unsettled_participation(participation_type: Participation
PolimecFunding::settle_bid(RuntimeOrigin::signed(alice()), project_id, bid.bidder.clone(), bid.id).unwrap()
}

let start = if participation_type == ParticipationType::Contribution { 1 } else { 0 };
for contribution in contributions_to_settle[start..].iter() {
PolimecFunding::settle_contribution(
RuntimeOrigin::signed(alice()),
project_id,
contribution.contributor.clone(),
contribution.id,
)
.unwrap()
}

let evaluations =
pallet_funding::Evaluations::<PolimecRuntime>::iter_prefix_values((project_id,)).collect_vec();
let bids = pallet_funding::Bids::<PolimecRuntime>::iter_prefix_values((project_id,)).collect_vec();
let contributions =
pallet_funding::Contributions::<PolimecRuntime>::iter_prefix_values((project_id,)).collect_vec();

if participation_type == ParticipationType::Evaluation {
assert_eq!(evaluations.len(), 1);
assert_eq!(bids.len(), 0);
assert_eq!(contributions.len(), 0);
} else if participation_type == ParticipationType::Bid {
assert_eq!(evaluations.len(), 0);
assert_eq!(bids.len(), 1);
assert_eq!(contributions.len(), 0);
} else {
assert_eq!(evaluations.len(), 0);
assert_eq!(bids.len(), 0);
assert_eq!(contributions.len(), 1);
}

(project_id, participants)
Expand All @@ -300,9 +269,8 @@ fn cannot_start_pallet_migration_with_unsettled_participations() {

let tup_1 = create_project_with_unsettled_participation(ParticipationType::Evaluation);
let tup_2 = create_project_with_unsettled_participation(ParticipationType::Bid);
let tup_3 = create_project_with_unsettled_participation(ParticipationType::Contribution);

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

for (project_id, _participants) in tups.into_iter() {
PolimecNet::execute_with(|| {
Expand Down
114 changes: 11 additions & 103 deletions integration-tests/src/tests/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::PolimecRuntime;
use frame_support::BoundedVec;
pub use pallet_funding::instantiator::{BidParams, ContributionParams, EvaluationParams};
pub use pallet_funding::instantiator::EvaluationParams;
use pallet_funding::{
BiddingTicketSizes, ContributingTicketSizes, CurrencyMetadata, ParticipantsAccountType, ParticipationMode,
PriceProviderOf, ProjectMetadata, ProjectMetadataOf, TicketSize,
BiddingTicketSizes, CurrencyMetadata, ParticipantsAccountType, PriceProviderOf, ProjectMetadata, ProjectMetadataOf,
TicketSize,
};
use sp_arithmetic::{FixedPointNumber, Percent};

use macros::generate_accounts;
use polimec_common::{assets::AcceptedFundingAsset, ProvideAssetPrice, USD_DECIMALS, USD_UNIT};
use polimec_runtime::{AccountId, PLMC};
use sp_runtime::{traits::ConstU32, Perquintill};
use ParticipationMode::{Classic, OTM};
use polimec_common::{
assets::AcceptedFundingAsset::{DOT, USDC, USDT, WETH},
ProvideAssetPrice, USD_DECIMALS, USD_UNIT,
};
use polimec_runtime::AccountId;
use sp_runtime::traits::ConstU32;

pub const IPFS_CID: &str = "QmeuJ24ffwLAZppQcgcggJs3n689bewednYkuc8Bx5Gngz";
pub const CT_DECIMALS: u8 = 18;
Expand All @@ -52,22 +53,12 @@ pub fn bounded_symbol() -> BoundedVec<u8, ConstU32<64>> {
pub fn ipfs_hash() -> BoundedVec<u8, ConstU32<96>> {
BoundedVec::try_from(IPFS_CID.as_bytes().to_vec()).unwrap()
}
pub fn default_weights() -> Vec<u8> {
vec![20u8, 15u8, 10u8, 25u8, 30u8]
}
pub fn default_bidder_modes() -> Vec<ParticipationMode> {
vec![Classic(1u8), Classic(6u8), OTM, OTM, Classic(3u8)]
}
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> {
ProjectMetadata {
token_information: CurrencyMetadata { name: bounded_name(), symbol: bounded_symbol(), decimals: CT_DECIMALS },
mainnet_token_max_supply: 8_000_000 * CT_UNIT,
total_allocation_size: 1_000_000 * CT_UNIT,
auction_round_allocation_percentage: Percent::from_percent(50u8),
minimum_price: PriceProviderOf::<PolimecRuntime>::calculate_decimals_aware_price(
sp_runtime::FixedU128::from_float(10.0),
USD_DECIMALS,
Expand All @@ -77,95 +68,12 @@ pub fn default_project_metadata(issuer: AccountId) -> ProjectMetadataOf<polimec_
bidding_ticket_sizes: BiddingTicketSizes {
professional: TicketSize::new(5000 * USD_UNIT, None),
institutional: TicketSize::new(5000 * USD_UNIT, None),
retail: TicketSize::new(10 * USD_UNIT, None),
phantom: Default::default(),
},
contributing_ticket_sizes: ContributingTicketSizes {
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(),
participation_currencies: vec![USDT, USDC, DOT, WETH].try_into().unwrap(),
funding_destination_account: issuer,
policy_ipfs_cid: Some(ipfs_hash()),
participants_account_type: ParticipantsAccountType::Polkadot,
}
}
pub fn default_evaluations() -> Vec<EvaluationParams<PolimecRuntime>> {
vec![
EvaluationParams::from((EVAL_1.into(), 500_000 * PLMC)),
EvaluationParams::from((EVAL_2.into(), 250_000 * PLMC)),
EvaluationParams::from((EVAL_3.into(), 320_000 * PLMC)),
]
}
pub fn default_bidders() -> Vec<AccountId> {
vec![BIDDER_1.into(), BIDDER_2.into(), BIDDER_3.into(), BIDDER_4.into(), BIDDER_5.into()]
}

pub fn default_bids() -> Vec<BidParams<PolimecRuntime>> {
let inst = IntegrationInstantiator::new(None);
let default_metadata = default_project_metadata(ISSUER.into());
let auction_allocation =
default_metadata.auction_round_allocation_percentage * default_metadata.total_allocation_size;
let auction_90_percent = Perquintill::from_percent(90) * auction_allocation;
let auction_usd_funding = default_metadata.minimum_price.saturating_mul_int(auction_90_percent);

inst.generate_bids_from_total_usd(
auction_usd_funding,
default_metadata.minimum_price,
default_weights(),
default_bidders(),
default_bidder_modes(),
)
}

pub fn default_community_contributions() -> Vec<ContributionParams<PolimecRuntime>> {
let inst = IntegrationInstantiator::new(None);

let default_metadata = default_project_metadata(ISSUER.into());

let auction_allocation =
default_metadata.auction_round_allocation_percentage * default_metadata.total_allocation_size;
let contribution_allocation = default_metadata.total_allocation_size - auction_allocation;

let eighty_percent_funding_ct = Perquintill::from_percent(80) * contribution_allocation;
let eighty_percent_funding_usd = default_metadata.minimum_price.saturating_mul_int(eighty_percent_funding_ct);

inst.generate_contributions_from_total_usd(
eighty_percent_funding_usd,
default_metadata.minimum_price,
default_weights(),
default_community_contributors(),
default_contributor_modes(),
)
}

pub fn default_remainder_contributions() -> Vec<ContributionParams<PolimecRuntime>> {
let inst = IntegrationInstantiator::new(None);

let default_metadata = default_project_metadata(ISSUER.into());

let auction_allocation =
default_metadata.auction_round_allocation_percentage * default_metadata.total_allocation_size;
let contribution_allocation = default_metadata.total_allocation_size - auction_allocation;

let ten_percent_auction = Perquintill::from_percent(10) * auction_allocation;
let ten_percent_auction_usd = default_metadata.minimum_price.saturating_mul_int(ten_percent_auction);
let ten_percent_contribution = Perquintill::from_percent(10) * contribution_allocation;
let ten_percent_contribution_usd = default_metadata.minimum_price.saturating_mul_int(ten_percent_contribution);

inst.generate_contributions_from_total_usd(
ten_percent_auction_usd + ten_percent_contribution_usd,
default_metadata.minimum_price,
vec![20u8, 15u8, 10u8, 25u8, 23u8, 7u8],
default_remainder_contributors(),
default_contributor_modes(),
)
}
pub fn default_community_contributors() -> Vec<AccountId> {
vec![BUYER_1.into(), BUYER_2.into(), BUYER_3.into(), BUYER_4.into(), BUYER_5.into()]
}

pub fn default_remainder_contributors() -> Vec<AccountId> {
vec![EVAL_4.into(), BUYER_6.into(), BIDDER_6.into(), EVAL_1.into(), BUYER_1.into(), BIDDER_1.into()]
}
Loading

0 comments on commit d2317e5

Please sign in to comment.