Skip to content

Commit

Permalink
Auction Round Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed Feb 5, 2025
1 parent afe14ff commit 3d334e6
Show file tree
Hide file tree
Showing 33 changed files with 1,319 additions and 1,710 deletions.
25 changes: 11 additions & 14 deletions integration-tests/src/tests/ct_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn get_migrations_for_participants(
for participant in participants {
let (status, migrations) =
pallet_funding::UserMigrations::<PolimecRuntime>::get((project_id, participant.clone())).unwrap();
user_migrations.insert(participant, (status, Migrations::from(migrations.into())));
user_migrations.insert(participant, (status, Migrations::from(migrations.to_vec())));
}
});
user_migrations
Expand Down Expand Up @@ -159,8 +159,8 @@ 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);
let evaluations = inst.generate_successful_evaluations(project_metadata.clone(), 10);
let bids = inst.generate_bids_from_total_ct_percent(project_metadata.clone(), 95, 30);
PolimecNet::execute_with(|| {
let project_id = inst.create_finished_project(project_metadata, ISSUER.into(), None, evaluations, bids);
assert_eq!(
Expand All @@ -171,10 +171,6 @@ fn create_settled_project() -> (ProjectId, Vec<AccountId>) {
pallet_funding::Evaluations::<PolimecRuntime>::iter_prefix_values((project_id,))
.map(|eval| eval.evaluator)
.chain(pallet_funding::Bids::<PolimecRuntime>::iter_prefix_values((project_id,)).map(|bid| bid.bidder))
.chain(
pallet_funding::Contributions::<PolimecRuntime>::iter_prefix_values((project_id,))
.map(|contribution| contribution.contributor),
)
.collect();
participants.sort();
participants.dedup();
Expand Down Expand Up @@ -211,8 +207,8 @@ fn create_project_with_unsettled_participation(participation_type: Participation
let mut inst = IntegrationInstantiator::new(None);
PolimecNet::execute_with(|| {
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 evaluations = inst.generate_successful_evaluations(project_metadata.clone(), 10);
let bids = inst.generate_bids_from_total_ct_percent(project_metadata.clone(), 95, 30);
let project_id = inst.create_finished_project(project_metadata, ISSUER.into(), None, evaluations, bids);

assert_eq!(
Expand All @@ -221,12 +217,12 @@ 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 bids_to_settle = inst.get_bids(project_id);

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(bids_to_settle.iter().map(|x| x.bidder.clone()))
.collect();
participants.sort();
participants.dedup();
Expand All @@ -242,9 +238,10 @@ fn create_project_with_unsettled_participation(participation_type: Participation
.unwrap()
}

let start = if participation_type == ParticipationType::Bid { 1 } else { 0 };
for bid in bids_to_settle[start..].iter() {
PolimecFunding::settle_bid(RuntimeOrigin::signed(alice()), project_id, bid.bidder.clone(), bid.id).unwrap()
let proposed_start = if participation_type == ParticipationType::Bid { 1 } else { 0 };
let end = if proposed_start == 1 { bids_to_settle.len() - 1 } else { bids_to_settle.len() };
for bid in bids_to_settle[..end].iter() {
PolimecFunding::settle_bid(RuntimeOrigin::signed(alice()), project_id, bid.id).unwrap()
}

let evaluations =
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/tests/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ 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),
retail: TicketSize::new(100 * USD_UNIT, None),
phantom: Default::default(),
},
participation_currencies: vec![USDT, USDC, DOT, WETH].try_into().unwrap(),
Expand Down
25 changes: 12 additions & 13 deletions integration-tests/src/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ fn participate_with_checks(
mut inst: IntegrationInstantiator,
project_id: ProjectId,
participation_type: ParticipationType,
participation_id: u32,
user: [u8; 32],
mode: ParticipationMode,
investor_type: InvestorType,
Expand Down Expand Up @@ -311,9 +310,6 @@ fn participate_with_checks(
if participation_type == ParticipationType::Bid {
PolimecFunding::bid(PolimecOrigin::signed(user.clone()), user_jwt, project_id, ct_amount, mode, funding_asset)
.unwrap();
let stored_bid = Bids::<PolimecRuntime>::get((project_id, user.clone(), participation_id));
// dbg!(&stored_bid);
assert!(stored_bid.is_some());
}

let post_participation_free_plmc = PolimecBalances::free_balance(user.clone());
Expand Down Expand Up @@ -392,14 +388,13 @@ fn e2e_test() {

assert_eq!(inst.go_to_next_state(project_id), ProjectStatus::AuctionRound);

for (bid_id, user, mode, investor_type, ct_amount, _price, funding_asset, funding_asset_ticket, plmc_bonded) in
for (_bid_id, user, mode, investor_type, ct_amount, _price, funding_asset, funding_asset_ticket, plmc_bonded) in
pre_wap_bids()
{
inst = participate_with_checks(
inst,
project_id,
ParticipationType::Bid,
bid_id,
user,
mode,
investor_type,
Expand All @@ -425,13 +420,8 @@ fn e2e_test() {
let prev_treasury_usdt_balance = PolimecForeignAssets::balance(USDT.id(), otm_project_sub_account.clone());
let prev_escrow_usdt_balance = PolimecForeignAssets::balance(USDT.id(), funding_escrow_account.clone());

PolimecFunding::settle_bid(
PolimecOrigin::signed(rejected_bidder.clone()),
project_id,
rejected_bidder.clone(),
rejected_bid_id,
)
.unwrap();
PolimecFunding::settle_bid(PolimecOrigin::signed(rejected_bidder.clone()), project_id, rejected_bid_id)
.unwrap();

let post_bid_free_plmc = PolimecBalances::free_balance(rejected_bidder.clone());
let post_bid_reserved_plmc = PolimecBalances::reserved_balance(rejected_bidder.clone());
Expand Down Expand Up @@ -663,3 +653,12 @@ fn e2e_test() {
}
});
}

#[test]
fn sandbox() {
let bid_weight = <PolimecRuntime as pallet_funding::Config>::WeightInfo::bid(1);
let process_weight = <PolimecRuntime as pallet_funding::Config>::WeightInfo::process_next_oversubscribed_bid();

dbg!(bid_weight);
dbg!(process_weight);
}
4 changes: 2 additions & 2 deletions integration-tests/src/tests/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ fn pallet_funding_works() {
assert_ok!(Oracle::feed_values(RuntimeOrigin::signed(charlie.clone()), values([4.84, 1.0, 1.0, 2500.0, 0.4])));

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 evaluations = inst.generate_successful_evaluations(project_metadata.clone(), 10);
let bids = inst.generate_bids_from_total_ct_percent(project_metadata.clone(), 95, 30);
let _project_id = inst.create_finished_project(project_metadata, ISSUER.into(), None, evaluations, bids);
});
}
3 changes: 1 addition & 2 deletions integration-tests/src/tests/runtime_apis.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::{constants::*, *};
use assets_common::runtime_api::runtime_decl_for_fungibles_api::FungiblesApiV2;
use frame_support::traits::{fungible::Mutate as FMutate, fungibles::Mutate, tokens::ConversionToAssetBalance};
use frame_support::traits::{fungible::Mutate as FMutate, fungibles::Mutate};
use polimec_common::assets::AcceptedFundingAsset;
use polimec_runtime::PLMCToAssetBalance;
use sp_arithmetic::FixedU128;
use xcm::v4::Junctions::X3;
use xcm_fee_payment_runtime_api::fees::runtime_decl_for_xcm_payment_api::XcmPaymentApiV1;
Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ benchmark-pallet chain="polimec-paseo-local" pallet="pallet-dispenser":
benchmark-extrinsics pallet="pallet-funding" extrinsics="*" :
cargo run --features runtime-benchmarks --profile=production -p polimec-node benchmark pallet \
--chain=polimec-paseo-local \
--steps=10 \
--repeat=5 \
--steps=50 \
--repeat=20 \
--pallet={{ pallet }} \
--no-storage-info \
--no-median-slopes \
Expand Down
Loading

0 comments on commit 3d334e6

Please sign in to comment.