Skip to content

Commit 8482103

Browse files
JuaniRioslrazovic
authored andcommitted
Funding Rounds Simplification
1 parent 308bb6d commit 8482103

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1150
-6472
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,4 @@ cumulus-pallet-session-benchmarking = { version = "16.0.0", default-features = f
247247
# Runtimes
248248
polimec-runtime = { path = "runtimes/polimec" }
249249
rococo-runtime-constants = { version = "14.0.0" }
250-
rococo-runtime = { version = "14.0.0" }
250+
rococo-runtime = { version = "14.0.0" }

integration-tests/src/constants.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -441,13 +441,13 @@ pub mod polimec {
441441
(dot_asset_id.clone(), alice_account.clone(), true, 100_000_000),
442442
(usdt_asset_id.clone(), alice_account.clone(), true, 70_000),
443443
(usdc_asset_id.clone(), alice_account.clone(), true, 70_000),
444-
(weth_asset_id, alice_account.clone(), true, 0_000_041_000_000_000_000),
444+
(weth_asset_id.clone(), alice_account.clone(), true, 0_000_041_000_000_000_000),
445445
],
446446
metadata: vec![
447447
(dot_asset_id, "Local DOT".as_bytes().to_vec(), "DOT".as_bytes().to_vec(), 10),
448448
(usdt_asset_id, "Local USDT".as_bytes().to_vec(), "USDT".as_bytes().to_vec(), 6),
449449
(usdc_asset_id.clone(), "Local USDC".as_bytes().to_vec(), "USDC".as_bytes().to_vec(), 6),
450-
(usdc_asset_id, "Local WETH".as_bytes().to_vec(), "WETH".as_bytes().to_vec(), 18),
450+
(weth_asset_id, "Local WETH".as_bytes().to_vec(), "WETH".as_bytes().to_vec(), 18),
451451
],
452452
accounts: vec![],
453453
},

integration-tests/src/tests/ct_migration.rs

+10-42
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,12 @@ fn migrations_are_vested(project_id: u32, accounts: Vec<AccountId>) {
157157

158158
fn create_settled_project() -> (ProjectId, Vec<AccountId>) {
159159
let mut inst = IntegrationInstantiator::new(None);
160+
161+
let project_metadata = default_project_metadata(ISSUER.into());
162+
let evaluations = inst.generate_successful_evaluations(project_metadata.clone(), 5);
163+
let bids = inst.generate_bids_from_total_ct_percent(project_metadata.clone(), 95, 8);
160164
PolimecNet::execute_with(|| {
161-
let project_id = inst.create_finished_project(
162-
default_project_metadata(ISSUER.into()),
163-
ISSUER.into(),
164-
None,
165-
default_evaluations(),
166-
default_bids(),
167-
default_community_contributions(),
168-
default_remainder_contributions(),
169-
);
165+
let project_id = inst.create_finished_project(project_metadata, ISSUER.into(), None, evaluations, bids);
170166
assert_eq!(
171167
inst.go_to_next_state(project_id),
172168
pallet_funding::ProjectStatus::SettlementStarted(FundingOutcome::Success)
@@ -214,15 +210,10 @@ fn full_pallet_migration_test() {
214210
fn create_project_with_unsettled_participation(participation_type: ParticipationType) -> (ProjectId, Vec<AccountId>) {
215211
let mut inst = IntegrationInstantiator::new(None);
216212
PolimecNet::execute_with(|| {
217-
let project_id = inst.create_finished_project(
218-
default_project_metadata(ISSUER.into()),
219-
ISSUER.into(),
220-
None,
221-
default_evaluations(),
222-
default_bids(),
223-
default_community_contributions(),
224-
default_remainder_contributions(),
225-
);
213+
let project_metadata = default_project_metadata(ISSUER.into());
214+
let evaluations = inst.generate_successful_evaluations(project_metadata.clone(), 5);
215+
let bids = inst.generate_bids_from_total_ct_percent(project_metadata.clone(), 95, 8);
216+
let project_id = inst.create_finished_project(project_metadata, ISSUER.into(), None, evaluations, bids);
226217

227218
assert_eq!(
228219
inst.go_to_next_state(project_id),
@@ -231,14 +222,11 @@ fn create_project_with_unsettled_participation(participation_type: Participation
231222
let evaluations_to_settle =
232223
pallet_funding::Evaluations::<PolimecRuntime>::iter_prefix_values((project_id,)).collect_vec();
233224
let bids_to_settle = pallet_funding::Bids::<PolimecRuntime>::iter_prefix_values((project_id,)).collect_vec();
234-
let contributions_to_settle =
235-
pallet_funding::Contributions::<PolimecRuntime>::iter_prefix_values((project_id,)).collect_vec();
236225

237226
let mut participants: Vec<AccountId> = evaluations_to_settle
238227
.iter()
239228
.map(|eval| eval.evaluator.clone())
240229
.chain(bids_to_settle.iter().map(|bid| bid.bidder.clone()))
241-
.chain(contributions_to_settle.iter().map(|contribution| contribution.contributor.clone()))
242230
.collect();
243231
participants.sort();
244232
participants.dedup();
@@ -259,35 +247,16 @@ fn create_project_with_unsettled_participation(participation_type: Participation
259247
PolimecFunding::settle_bid(RuntimeOrigin::signed(alice()), project_id, bid.bidder.clone(), bid.id).unwrap()
260248
}
261249

262-
let start = if participation_type == ParticipationType::Contribution { 1 } else { 0 };
263-
for contribution in contributions_to_settle[start..].iter() {
264-
PolimecFunding::settle_contribution(
265-
RuntimeOrigin::signed(alice()),
266-
project_id,
267-
contribution.contributor.clone(),
268-
contribution.id,
269-
)
270-
.unwrap()
271-
}
272-
273250
let evaluations =
274251
pallet_funding::Evaluations::<PolimecRuntime>::iter_prefix_values((project_id,)).collect_vec();
275252
let bids = pallet_funding::Bids::<PolimecRuntime>::iter_prefix_values((project_id,)).collect_vec();
276-
let contributions =
277-
pallet_funding::Contributions::<PolimecRuntime>::iter_prefix_values((project_id,)).collect_vec();
278253

279254
if participation_type == ParticipationType::Evaluation {
280255
assert_eq!(evaluations.len(), 1);
281256
assert_eq!(bids.len(), 0);
282-
assert_eq!(contributions.len(), 0);
283257
} else if participation_type == ParticipationType::Bid {
284258
assert_eq!(evaluations.len(), 0);
285259
assert_eq!(bids.len(), 1);
286-
assert_eq!(contributions.len(), 0);
287-
} else {
288-
assert_eq!(evaluations.len(), 0);
289-
assert_eq!(bids.len(), 0);
290-
assert_eq!(contributions.len(), 1);
291260
}
292261

293262
(project_id, participants)
@@ -300,9 +269,8 @@ fn cannot_start_pallet_migration_with_unsettled_participations() {
300269

301270
let tup_1 = create_project_with_unsettled_participation(ParticipationType::Evaluation);
302271
let tup_2 = create_project_with_unsettled_participation(ParticipationType::Bid);
303-
let tup_3 = create_project_with_unsettled_participation(ParticipationType::Contribution);
304272

305-
let tups = vec![tup_1, tup_2, tup_3];
273+
let tups = vec![tup_1, tup_2];
306274

307275
for (project_id, _participants) in tups.into_iter() {
308276
PolimecNet::execute_with(|| {

integration-tests/src/tests/defaults.rs

+11-103
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
use crate::PolimecRuntime;
1717
use frame_support::BoundedVec;
18-
pub use pallet_funding::instantiator::{BidParams, ContributionParams, EvaluationParams};
18+
pub use pallet_funding::instantiator::EvaluationParams;
1919
use pallet_funding::{
20-
BiddingTicketSizes, ContributingTicketSizes, CurrencyMetadata, ParticipantsAccountType, ParticipationMode,
21-
PriceProviderOf, ProjectMetadata, ProjectMetadataOf, TicketSize,
20+
BiddingTicketSizes, CurrencyMetadata, ParticipantsAccountType, PriceProviderOf, ProjectMetadata, ProjectMetadataOf,
21+
TicketSize,
2222
};
23-
use sp_arithmetic::{FixedPointNumber, Percent};
2423

2524
use macros::generate_accounts;
26-
use polimec_common::{assets::AcceptedFundingAsset, ProvideAssetPrice, USD_DECIMALS, USD_UNIT};
27-
use polimec_runtime::{AccountId, PLMC};
28-
use sp_runtime::{traits::ConstU32, Perquintill};
29-
use ParticipationMode::{Classic, OTM};
25+
use polimec_common::{
26+
assets::AcceptedFundingAsset::{DOT, USDC, USDT, WETH},
27+
ProvideAssetPrice, USD_DECIMALS, USD_UNIT,
28+
};
29+
use polimec_runtime::AccountId;
30+
use sp_runtime::traits::ConstU32;
3031

3132
pub const IPFS_CID: &str = "QmeuJ24ffwLAZppQcgcggJs3n689bewednYkuc8Bx5Gngz";
3233
pub const CT_DECIMALS: u8 = 18;
@@ -52,22 +53,12 @@ pub fn bounded_symbol() -> BoundedVec<u8, ConstU32<64>> {
5253
pub fn ipfs_hash() -> BoundedVec<u8, ConstU32<96>> {
5354
BoundedVec::try_from(IPFS_CID.as_bytes().to_vec()).unwrap()
5455
}
55-
pub fn default_weights() -> Vec<u8> {
56-
vec![20u8, 15u8, 10u8, 25u8, 30u8]
57-
}
58-
pub fn default_bidder_modes() -> Vec<ParticipationMode> {
59-
vec![Classic(1u8), Classic(6u8), OTM, OTM, Classic(3u8)]
60-
}
61-
pub fn default_contributor_modes() -> Vec<ParticipationMode> {
62-
vec![Classic(1u8), Classic(1u8), OTM, OTM, Classic(3u8)]
63-
}
6456

6557
pub fn default_project_metadata(issuer: AccountId) -> ProjectMetadataOf<polimec_runtime::Runtime> {
6658
ProjectMetadata {
6759
token_information: CurrencyMetadata { name: bounded_name(), symbol: bounded_symbol(), decimals: CT_DECIMALS },
6860
mainnet_token_max_supply: 8_000_000 * CT_UNIT,
6961
total_allocation_size: 1_000_000 * CT_UNIT,
70-
auction_round_allocation_percentage: Percent::from_percent(50u8),
7162
minimum_price: PriceProviderOf::<PolimecRuntime>::calculate_decimals_aware_price(
7263
sp_runtime::FixedU128::from_float(10.0),
7364
USD_DECIMALS,
@@ -77,95 +68,12 @@ pub fn default_project_metadata(issuer: AccountId) -> ProjectMetadataOf<polimec_
7768
bidding_ticket_sizes: BiddingTicketSizes {
7869
professional: TicketSize::new(5000 * USD_UNIT, None),
7970
institutional: TicketSize::new(5000 * USD_UNIT, None),
71+
retail: TicketSize::new(10 * USD_UNIT, None),
8072
phantom: Default::default(),
8173
},
82-
contributing_ticket_sizes: ContributingTicketSizes {
83-
retail: TicketSize::new(USD_UNIT, None),
84-
professional: TicketSize::new(USD_UNIT, None),
85-
institutional: TicketSize::new(USD_UNIT, None),
86-
phantom: Default::default(),
87-
},
88-
participation_currencies: vec![AcceptedFundingAsset::USDT].try_into().unwrap(),
74+
participation_currencies: vec![USDT, USDC, DOT, WETH].try_into().unwrap(),
8975
funding_destination_account: issuer,
9076
policy_ipfs_cid: Some(ipfs_hash()),
9177
participants_account_type: ParticipantsAccountType::Polkadot,
9278
}
9379
}
94-
pub fn default_evaluations() -> Vec<EvaluationParams<PolimecRuntime>> {
95-
vec![
96-
EvaluationParams::from((EVAL_1.into(), 500_000 * PLMC)),
97-
EvaluationParams::from((EVAL_2.into(), 250_000 * PLMC)),
98-
EvaluationParams::from((EVAL_3.into(), 320_000 * PLMC)),
99-
]
100-
}
101-
pub fn default_bidders() -> Vec<AccountId> {
102-
vec![BIDDER_1.into(), BIDDER_2.into(), BIDDER_3.into(), BIDDER_4.into(), BIDDER_5.into()]
103-
}
104-
105-
pub fn default_bids() -> Vec<BidParams<PolimecRuntime>> {
106-
let inst = IntegrationInstantiator::new(None);
107-
let default_metadata = default_project_metadata(ISSUER.into());
108-
let auction_allocation =
109-
default_metadata.auction_round_allocation_percentage * default_metadata.total_allocation_size;
110-
let auction_90_percent = Perquintill::from_percent(90) * auction_allocation;
111-
let auction_usd_funding = default_metadata.minimum_price.saturating_mul_int(auction_90_percent);
112-
113-
inst.generate_bids_from_total_usd(
114-
auction_usd_funding,
115-
default_metadata.minimum_price,
116-
default_weights(),
117-
default_bidders(),
118-
default_bidder_modes(),
119-
)
120-
}
121-
122-
pub fn default_community_contributions() -> Vec<ContributionParams<PolimecRuntime>> {
123-
let inst = IntegrationInstantiator::new(None);
124-
125-
let default_metadata = default_project_metadata(ISSUER.into());
126-
127-
let auction_allocation =
128-
default_metadata.auction_round_allocation_percentage * default_metadata.total_allocation_size;
129-
let contribution_allocation = default_metadata.total_allocation_size - auction_allocation;
130-
131-
let eighty_percent_funding_ct = Perquintill::from_percent(80) * contribution_allocation;
132-
let eighty_percent_funding_usd = default_metadata.minimum_price.saturating_mul_int(eighty_percent_funding_ct);
133-
134-
inst.generate_contributions_from_total_usd(
135-
eighty_percent_funding_usd,
136-
default_metadata.minimum_price,
137-
default_weights(),
138-
default_community_contributors(),
139-
default_contributor_modes(),
140-
)
141-
}
142-
143-
pub fn default_remainder_contributions() -> Vec<ContributionParams<PolimecRuntime>> {
144-
let inst = IntegrationInstantiator::new(None);
145-
146-
let default_metadata = default_project_metadata(ISSUER.into());
147-
148-
let auction_allocation =
149-
default_metadata.auction_round_allocation_percentage * default_metadata.total_allocation_size;
150-
let contribution_allocation = default_metadata.total_allocation_size - auction_allocation;
151-
152-
let ten_percent_auction = Perquintill::from_percent(10) * auction_allocation;
153-
let ten_percent_auction_usd = default_metadata.minimum_price.saturating_mul_int(ten_percent_auction);
154-
let ten_percent_contribution = Perquintill::from_percent(10) * contribution_allocation;
155-
let ten_percent_contribution_usd = default_metadata.minimum_price.saturating_mul_int(ten_percent_contribution);
156-
157-
inst.generate_contributions_from_total_usd(
158-
ten_percent_auction_usd + ten_percent_contribution_usd,
159-
default_metadata.minimum_price,
160-
vec![20u8, 15u8, 10u8, 25u8, 23u8, 7u8],
161-
default_remainder_contributors(),
162-
default_contributor_modes(),
163-
)
164-
}
165-
pub fn default_community_contributors() -> Vec<AccountId> {
166-
vec![BUYER_1.into(), BUYER_2.into(), BUYER_3.into(), BUYER_4.into(), BUYER_5.into()]
167-
}
168-
169-
pub fn default_remainder_contributors() -> Vec<AccountId> {
170-
vec![EVAL_4.into(), BUYER_6.into(), BIDDER_6.into(), EVAL_1.into(), BUYER_1.into(), BIDDER_1.into()]
171-
}

0 commit comments

Comments
 (0)