Skip to content

Commit

Permalink
Early bidder release
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed Jan 30, 2025
1 parent 079b73d commit c7923f0
Show file tree
Hide file tree
Showing 31 changed files with 861 additions and 1,399 deletions.
153 changes: 153 additions & 0 deletions benchmarked-extrinsics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// Polimec Blockchain – https://www.polimec.org/
// Copyright (C) Polimec 2022. All rights reserved.

// The Polimec Blockchain is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// The Polimec Blockchain is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// If you feel like getting in touch with us, you can do so at [email protected]


//! Autogenerated weights for `pallet_funding`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 39.0.0
//! DATE: 2025-01-29, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `Mac.home`, CPU: `<UNKNOWN>`
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("polimec-paseo-local")`, DB CACHE: `1024`
// Executed Command:
// target/production/polimec-node
// benchmark
// pallet
// --chain=polimec-paseo-local
// --steps=50
// --repeat=20
// --pallet=pallet-funding
// --no-storage-info
// --no-median-slopes
// --no-min-squares
// --extrinsic=bid
// --wasm-execution=compiled
// --heap-pages=4096
// --output=benchmarked-extrinsics.rs
// --template=./.maintain/frame-weight-template.hbs

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(missing_docs)]

use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use core::marker::PhantomData;

/// Weight functions needed for `pallet_funding`.
pub trait WeightInfo {
fn bid(x: u32, ) -> Weight;
}

/// Weights for `pallet_funding` using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: `Timestamp::Now` (r:1 w:0)
/// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
/// Storage: `Funding::ProjectsMetadata` (r:1 w:0)
/// Proof: `Funding::ProjectsMetadata` (`max_values`: None, `max_size`: Some(437), added: 2912, mode: `MaxEncodedLen`)
/// Storage: `Funding::ProjectsDetails` (r:1 w:0)
/// Proof: `Funding::ProjectsDetails` (`max_values`: None, `max_size`: Some(347), added: 2822, mode: `MaxEncodedLen`)
/// Storage: `Funding::Buckets` (r:1 w:1)
/// Proof: `Funding::Buckets` (`max_values`: None, `max_size`: Some(100), added: 2575, mode: `MaxEncodedLen`)
/// Storage: `Funding::NextBidId` (r:1 w:1)
/// Proof: `Funding::NextBidId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
/// Storage: `Funding::BidBucketBounds` (r:11 w:10)
/// Proof: `Funding::BidBucketBounds` (`max_values`: None, `max_size`: Some(60), added: 2535, mode: `MaxEncodedLen`)
/// Storage: `Funding::AuctionBoughtUSD` (r:1 w:1)
/// Proof: `Funding::AuctionBoughtUSD` (`max_values`: None, `max_size`: Some(118), added: 2593, mode: `MaxEncodedLen`)
/// Storage: `Oracle::Values` (r:2 w:0)
/// Proof: `Oracle::Values` (`max_values`: None, `max_size`: Some(634), added: 3109, mode: `MaxEncodedLen`)
/// Storage: `ForeignAssets::Metadata` (r:1 w:0)
/// Proof: `ForeignAssets::Metadata` (`max_values`: None, `max_size`: Some(738), added: 3213, mode: `MaxEncodedLen`)
/// Storage: `Funding::Evaluations` (r:1 w:0)
/// Proof: `Funding::Evaluations` (`max_values`: None, `max_size`: Some(337), added: 2812, mode: `MaxEncodedLen`)
/// Storage: `Balances::Holds` (r:1 w:1)
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`)
/// Storage: `ForeignAssets::Asset` (r:1 w:1)
/// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`)
/// Storage: `ForeignAssets::Account` (r:2 w:2)
/// Proof: `ForeignAssets::Account` (`max_values`: None, `max_size`: Some(732), added: 3207, mode: `MaxEncodedLen`)
/// Storage: `Funding::OutbidBidsCutoff` (r:1 w:1)
/// Proof: `Funding::OutbidBidsCutoff` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`)
/// Storage: `Funding::Bids` (r:999 w:19)
/// Proof: `Funding::Bids` (`max_values`: None, `max_size`: Some(341), added: 2816, mode: `MaxEncodedLen`)
/// The range of component `x` is `[1, 1000]`.
fn bid(x: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `4850 + x * (226 ±0)`
// Estimated: `28875 + x * (2816 ±0)`
// Minimum execution time: 829_000_000 picoseconds.
Weight::from_parts(767_882_619, 28875)
// Standard Error: 8_838
.saturating_add(Weight::from_parts(5_852_038, 0).saturating_mul(x.into()))
.saturating_add(T::DbWeight::get().reads(26_u64))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into())))
.saturating_add(T::DbWeight::get().writes(36_u64))
.saturating_add(Weight::from_parts(0, 2816).saturating_mul(x.into()))
}
}

// For backwards compatibility and tests.
impl WeightInfo for () {
/// Storage: `Timestamp::Now` (r:1 w:0)
/// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
/// Storage: `Funding::ProjectsMetadata` (r:1 w:0)
/// Proof: `Funding::ProjectsMetadata` (`max_values`: None, `max_size`: Some(437), added: 2912, mode: `MaxEncodedLen`)
/// Storage: `Funding::ProjectsDetails` (r:1 w:0)
/// Proof: `Funding::ProjectsDetails` (`max_values`: None, `max_size`: Some(347), added: 2822, mode: `MaxEncodedLen`)
/// Storage: `Funding::Buckets` (r:1 w:1)
/// Proof: `Funding::Buckets` (`max_values`: None, `max_size`: Some(100), added: 2575, mode: `MaxEncodedLen`)
/// Storage: `Funding::NextBidId` (r:1 w:1)
/// Proof: `Funding::NextBidId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
/// Storage: `Funding::BidBucketBounds` (r:11 w:10)
/// Proof: `Funding::BidBucketBounds` (`max_values`: None, `max_size`: Some(60), added: 2535, mode: `MaxEncodedLen`)
/// Storage: `Funding::AuctionBoughtUSD` (r:1 w:1)
/// Proof: `Funding::AuctionBoughtUSD` (`max_values`: None, `max_size`: Some(118), added: 2593, mode: `MaxEncodedLen`)
/// Storage: `Oracle::Values` (r:2 w:0)
/// Proof: `Oracle::Values` (`max_values`: None, `max_size`: Some(634), added: 3109, mode: `MaxEncodedLen`)
/// Storage: `ForeignAssets::Metadata` (r:1 w:0)
/// Proof: `ForeignAssets::Metadata` (`max_values`: None, `max_size`: Some(738), added: 3213, mode: `MaxEncodedLen`)
/// Storage: `Funding::Evaluations` (r:1 w:0)
/// Proof: `Funding::Evaluations` (`max_values`: None, `max_size`: Some(337), added: 2812, mode: `MaxEncodedLen`)
/// Storage: `Balances::Holds` (r:1 w:1)
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`)
/// Storage: `ForeignAssets::Asset` (r:1 w:1)
/// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(808), added: 3283, mode: `MaxEncodedLen`)
/// Storage: `ForeignAssets::Account` (r:2 w:2)
/// Proof: `ForeignAssets::Account` (`max_values`: None, `max_size`: Some(732), added: 3207, mode: `MaxEncodedLen`)
/// Storage: `Funding::OutbidBidsCutoff` (r:1 w:1)
/// Proof: `Funding::OutbidBidsCutoff` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`)
/// Storage: `Funding::Bids` (r:999 w:19)
/// Proof: `Funding::Bids` (`max_values`: None, `max_size`: Some(341), added: 2816, mode: `MaxEncodedLen`)
/// The range of component `x` is `[1, 1000]`.
fn bid(x: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `4850 + x * (226 ±0)`
// Estimated: `28875 + x * (2816 ±0)`
// Minimum execution time: 829_000_000 picoseconds.
Weight::from_parts(767_882_619, 28875)
// Standard Error: 8_838
.saturating_add(Weight::from_parts(5_852_038, 0).saturating_mul(x.into()))
.saturating_add(RocksDbWeight::get().reads(26_u64))
.saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(x.into())))
.saturating_add(RocksDbWeight::get().writes(36_u64))
.saturating_add(Weight::from_parts(0, 2816).saturating_mul(x.into()))
}
}
19 changes: 10 additions & 9 deletions integration-tests/src/tests/ct_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use frame_support::WeakBoundedVec;
use crate::{constants::PricesBuilder, *};
use frame_support::traits::{fungible::Mutate, fungibles::Inspect};
use itertools::Itertools;
Expand Down Expand Up @@ -70,7 +71,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 +160,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 Down Expand Up @@ -207,8 +208,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 @@ -217,12 +218,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 = PolimecFunding::get_ordered_bid_settlements(project_id);
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(|x| x.1.clone()))
.chain(bids_to_settle.iter().map(|x| x.bidder.clone()))
.collect();
participants.sort();
participants.dedup();
Expand All @@ -240,8 +241,8 @@ fn create_project_with_unsettled_participation(participation_type: Participation

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 (project_id, bidder, id) in bids_to_settle[..end].iter() {
PolimecFunding::settle_bid(RuntimeOrigin::signed(alice()), *project_id, bidder.clone(), *id).unwrap()
for bid in bids_to_settle[..end].iter() {
PolimecFunding::settle_bid(RuntimeOrigin::signed(alice()), project_id, bid.original_ct_usd_price, 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
26 changes: 22 additions & 4 deletions integration-tests/src/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,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 @@ -425,10 +422,11 @@ 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());

let rejected_bidder_bid = inst.get_bid(rejected_bid_id);
PolimecFunding::settle_bid(
PolimecOrigin::signed(rejected_bidder.clone()),
project_id,
rejected_bidder.clone(),
rejected_bidder_bid.original_ct_usd_price,
rejected_bid_id,
)
.unwrap();
Expand Down Expand Up @@ -663,3 +661,23 @@ fn e2e_test() {
}
});
}

#[test]
fn sandbox() {
fn bid(x: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `4850 + x * (226 ±0)`
// Estimated: `28875 + x * (2816 ±0)`
// Minimum execution time: 829_000_000 picoseconds.
Weight::from_parts(767_882_619, 28875)
// Standard Error: 8_838
.saturating_add(Weight::from_parts(5_852_038, 0).saturating_mul(x.into()))
.saturating_add(<PolimecRuntime as frame_system::Config>::DbWeight::get().reads(26_u64))
.saturating_add(<PolimecRuntime as frame_system::Config>::DbWeight::get().reads((1_u64).saturating_mul(x.into())))
.saturating_add(<PolimecRuntime as frame_system::Config>::DbWeight::get().writes(36_u64))
.saturating_add(Weight::from_parts(0, 2816).saturating_mul(x.into()))
}

let max_weight = bid(1000);
dbg!(max_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);
});
}
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 c7923f0

Please sign in to comment.