Skip to content

Commit

Permalink
remove AuctionInitializePeriod
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed Aug 13, 2024
1 parent 0f2acf1 commit aa77143
Show file tree
Hide file tree
Showing 14 changed files with 6 additions and 179 deletions.
11 changes: 5 additions & 6 deletions pallets/funding/src/functions/2_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,20 @@ impl<T: Config> Pallet<T> {

// * Branch in possible project paths *
// Successful path
if is_funded {
return Self::transition_project(
return if is_funded {
Self::transition_project(
project_id,
project_details,
ProjectStatus::EvaluationRound,
ProjectStatus::AuctionInitializePeriod,
Some(T::AuctionInitializePeriodDuration::get()),
ProjectStatus::AuctionRound,
Some(T::AuctionRoundDuration::get()),
false,
)
// Unsuccessful path
} else {
let issuer_did = project_details.issuer_did.clone();
DidWithActiveProjects::<T>::set(issuer_did, None);
// * Update storage *
return Self::transition_project(
Self::transition_project(
project_id,
project_details,
ProjectStatus::EvaluationRound,
Expand Down
39 changes: 0 additions & 39 deletions pallets/funding/src/functions/3_auction.rs
Original file line number Diff line number Diff line change
@@ -1,45 +1,6 @@
use super::*;

impl<T: Config> Pallet<T> {
/// Called by user extrinsic
/// Starts the auction round for a project. From the next block forward, any professional or
/// institutional user can set bids for a token_amount/token_price pair.
/// Any bids from this point until the auction_closing starts will be considered as valid.
///
/// # Arguments
/// * `project_id` - The project identifier
///
/// # Storage access
/// * [`ProjectsDetails`] - Get the project information, and check if the project is in the correct
/// round, and the current block is between the defined start and end blocks of the initialize period.
/// Update the project information with the new round status and transition points in case of success.
///
/// # Success Path
/// The validity checks pass, and the project is transitioned to the Auction Opening round.
/// The project is scheduled to be transitioned automatically by `on_initialize` at the end of the
/// auction opening round.
///
/// # Next step
/// Professional and Institutional users set bids for the project using the [`bid`](Self::bid) extrinsic.
/// Later on, `on_initialize` transitions the project into the closing auction round, by calling
/// [`do_auction_closing`](Self::do_auction_closing).
#[transactional]
pub fn do_start_auction(caller: AccountIdOf<T>, project_id: ProjectId) -> DispatchResult {
// * Get variables *
let project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
// issuer_account can start the auction opening round during the Auction Initialize Period.
let skip_round_end_check = caller == project_details.issuer_account;

Self::transition_project(
project_id,
project_details,
ProjectStatus::AuctionInitializePeriod,
ProjectStatus::AuctionRound,
Some(T::AuctionRoundDuration::get()),
skip_round_end_check,
)
}

/// Decides which bids are accepted and which are rejected.
/// Deletes and refunds the rejected ones, and prepares the project for the WAP calculation the next block
#[transactional]
Expand Down
4 changes: 0 additions & 4 deletions pallets/funding/src/instantiator/chain_interactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,6 @@ impl<
ProjectStatus::EvaluationRound => {
self.execute(|| <Pallet<T>>::do_end_evaluation(project_id).unwrap());
},
ProjectStatus::AuctionInitializePeriod => {
self.execute(|| <Pallet<T>>::do_start_auction(issuer, project_id).unwrap());
},
ProjectStatus::AuctionRound => {
self.execute(|| <Pallet<T>>::do_end_auction(project_id).unwrap());
},
Expand Down Expand Up @@ -503,7 +500,6 @@ impl<

self.evaluation_assertions(project_id, expected_remaining_plmc, plmc_eval_deposits, expected_total_supply);

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

project_id
Expand Down
14 changes: 0 additions & 14 deletions pallets/funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ pub mod pallet {
+ OnIdle<BlockNumberFor<Self>>
+ OnInitialize<BlockNumberFor<Self>>;

/// The time window (expressed in number of blocks) that an issuer has to start the auction round.
#[pallet::constant]
type AuctionInitializePeriodDuration: Get<BlockNumberFor<Self>>;

/// The inner balance type we will use for all of our outer currency types. (e.g native, funding, CTs)
type Balance: Balance + From<u64> + FixedPointOperand + MaybeSerializeDeserialize + Into<u128>;

Expand Down Expand Up @@ -873,16 +869,6 @@ pub mod pallet {
Self::do_end_evaluation(project_id)
}

/// Starts the auction round for a project. From the next block forward, any professional or
/// institutional user can set bids for a token_amount/token_price pair.
/// Any bids from this point until the auction_closing starts, will be considered as valid.
#[pallet::call_index(6)]
#[pallet::weight(WeightInfoOf::<T>::start_auction_manually(1))]
pub fn start_auction(origin: OriginFor<T>, project_id: ProjectId) -> DispatchResult {
let account = ensure_signed(origin)?;
Self::do_start_auction(account, project_id)
}

/// Bid for a project in the Auction round
#[pallet::call_index(7)]
#[pallet::weight(
Expand Down
2 changes: 0 additions & 2 deletions pallets/funding/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ pub const HOURS: BlockNumber = 300u64;
// We need all durations to use different times to catch bugs in the tests.
parameter_types! {
pub const EvaluationRoundDuration: BlockNumber = 10u64;
pub const AuctionInitializePeriodDuration: BlockNumber = 12u64;
pub const AuctionRoundDuration: BlockNumber = 15u64;
pub const CommunityRoundDuration: BlockNumber = 18u64;
pub const RemainderRoundDuration: BlockNumber = 6u64;
Expand Down Expand Up @@ -397,7 +396,6 @@ impl Config for TestRuntime {
type AccountId32Conversion = DummyConverter;
type AllPalletsWithoutSystem =
(Balances, ContributionTokens, ForeignAssets, PolimecFunding, LinearRelease, RandomnessCollectiveFlip);
type AuctionInitializePeriodDuration = AuctionInitializePeriodDuration;
type AuctionRoundDuration = AuctionRoundDuration;
type Balance = Balance;
type BlockNumber = BlockNumber;
Expand Down
2 changes: 0 additions & 2 deletions pallets/funding/src/tests/1_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ mod create_project_extrinsic {

inst.evaluate_for_users(1, default_evaluations()).unwrap();

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

inst.bid_for_users(1, failing_bids).unwrap();
Expand Down Expand Up @@ -206,7 +205,6 @@ mod create_project_extrinsic {
assert_eq!(inst.go_to_next_state(2), ProjectStatus::EvaluationRound);
inst.evaluate_for_users(2, default_evaluations()).unwrap();

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

inst.bid_for_users(2, default_bids()).unwrap();
Expand Down
3 changes: 0 additions & 3 deletions pallets/funding/src/tests/2_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ mod round_flow {
let old_price = <TestRuntime as Config>::PriceProvider::get_price(PLMC_FOREIGN_ID).unwrap();
PRICE_MAP.with_borrow_mut(|map| map.insert(PLMC_FOREIGN_ID, old_price / 2.into()));

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

// Increasing the price before the end doesn't make a project under the threshold succeed.
Expand Down Expand Up @@ -178,7 +177,6 @@ mod round_flow {
)));

// The evaluation should succeed when we bond the threshold PLMC amount in total.
assert_eq!(inst.go_to_next_state(project_id), ProjectStatus::AuctionInitializePeriod);
assert_eq!(inst.go_to_next_state(project_id), ProjectStatus::AuctionRound);
};

Expand Down Expand Up @@ -635,7 +633,6 @@ mod evaluate_extrinsic {
inst.mint_plmc_to(new_plmc_required.clone());
inst.evaluate_for_users(project_id, new_evaluations).unwrap();

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

assert!(matches!(inst.go_to_next_state(project_id), ProjectStatus::CommunityRound(_)));
Expand Down
97 changes: 0 additions & 97 deletions pallets/funding/src/tests/3_auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,103 +349,6 @@ mod round_flow {
}
}

#[cfg(test)]
mod start_auction_extrinsic {
use super::*;

#[cfg(test)]
mod success {
use super::*;

#[test]
fn anyone_can_start_auction_after_initialize_period() {
let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext())));
let project_id = inst.create_evaluating_project(default_project_metadata(ISSUER_1), ISSUER_1, None);
let evaluations = default_evaluations();
let required_plmc = inst.calculate_evaluation_plmc_spent(evaluations.clone(), true);

inst.mint_plmc_to(required_plmc);
inst.evaluate_for_users(project_id, evaluations).unwrap();

assert_eq!(inst.go_to_next_state(project_id), ProjectStatus::AuctionInitializePeriod);
let end_block = inst.get_project_details(project_id).round_duration.end().unwrap();
inst.jump_to_block(end_block);

inst.execute(|| PolimecFunding::start_auction(RuntimeOrigin::signed(420u32), project_id)).unwrap();

assert_eq!(inst.get_project_details(project_id).status, ProjectStatus::AuctionRound);
}

#[test]
fn issuer_can_start_auction_before_initialize_period_end() {
let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext())));
let project_id = inst.create_evaluating_project(default_project_metadata(ISSUER_1), ISSUER_1, None);
let evaluations = default_evaluations();
let required_plmc = inst.calculate_evaluation_plmc_spent(evaluations.clone(), true);
inst.mint_plmc_to(required_plmc);
inst.evaluate_for_users(project_id, evaluations).unwrap();

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

inst.execute(|| Pallet::<TestRuntime>::start_auction(RuntimeOrigin::signed(ISSUER_1), project_id)).unwrap();
assert_eq!(inst.get_project_details(project_id).status, ProjectStatus::AuctionRound);
}
}

#[cfg(test)]
mod failure {
use super::*;

#[test]
fn anyone_cannot_start_auction_before_initialize_period() {
let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext())));
let project_id = inst.create_evaluating_project(default_project_metadata(ISSUER_1), ISSUER_1, None);
let evaluations = default_evaluations();
let required_plmc = inst.calculate_evaluation_plmc_spent(evaluations.clone(), true);

inst.mint_plmc_to(required_plmc);
inst.evaluate_for_users(project_id, evaluations).unwrap();

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

inst.execute(|| {
assert_noop!(
PolimecFunding::start_auction(RuntimeOrigin::signed(420u32), project_id),
Error::<TestRuntime>::TooEarlyForRound
);
});

assert_eq!(inst.get_project_details(project_id).status, ProjectStatus::AuctionInitializePeriod);
}

#[test]
fn issuer_cannot_start_auction_manually_before_evaluation_finishes() {
let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext())));
let project_id = inst.create_evaluating_project(default_project_metadata(ISSUER_1), ISSUER_1, None);
inst.execute(|| {
assert_noop!(
PolimecFunding::start_auction(RuntimeOrigin::signed(ISSUER_1), project_id),
Error::<TestRuntime>::IncorrectRound
);
});
}

#[test]
fn cannot_start_auction_manually_if_evaluation_fails() {
let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext())));
let project_id = inst.create_evaluating_project(default_project_metadata(ISSUER_1), ISSUER_1, None);
assert_eq!(inst.go_to_next_state(project_id), ProjectStatus::FundingFailed);

inst.execute(|| {
assert_noop!(
PolimecFunding::start_auction(RuntimeOrigin::signed(ISSUER_1), project_id),
Error::<TestRuntime>::IncorrectRound
);
});
}
}
}

#[cfg(test)]
mod bid_extrinsic {
use super::*;
Expand Down
1 change: 0 additions & 1 deletion pallets/funding/src/tests/5_funding_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ mod end_funding_extrinsic {
project_details.funding_end_block,
Some(
EvaluationRoundDuration::get() +
AuctionInitializePeriodDuration::get() +
AuctionRoundDuration::get() +
CommunityRoundDuration::get() +
RemainderRoundDuration::get() +
Expand Down
7 changes: 1 addition & 6 deletions pallets/funding/src/tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,9 @@ fn project_state_transition_event() {

let mut desired_transitions = vec![
ProjectStatus::EvaluationRound,
ProjectStatus::AuctionInitializePeriod,
ProjectStatus::AuctionRound,
ProjectStatus::CommunityRound(
EvaluationRoundDuration::get() +
AuctionInitializePeriodDuration::get() +
AuctionRoundDuration::get() +
CommunityRoundDuration::get() +
1u64,
EvaluationRoundDuration::get() + AuctionRoundDuration::get() + CommunityRoundDuration::get() + 1u64,
),
ProjectStatus::FundingSuccessful,
ProjectStatus::SettlementStarted(FundingOutcome::Success),
Expand Down
1 change: 0 additions & 1 deletion pallets/funding/src/tests/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ fn all_project_participations_by_did() {
});
}

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

inst.bid_for_users(project_id, bids[..1].to_vec()).unwrap();
Expand Down
1 change: 0 additions & 1 deletion pallets/funding/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,6 @@ pub mod inner_types {
#[default]
Application,
EvaluationRound,
AuctionInitializePeriod,
AuctionRound,
CommunityRound(BlockNumber),
FundingFailed,
Expand Down
2 changes: 0 additions & 2 deletions runtimes/polimec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ impl Contains<RuntimeCall> for BaseCallFilter {
pallet_funding::Call::start_evaluation { .. } |
pallet_funding::Call::evaluate { .. } |
pallet_funding::Call::end_evaluation { .. } |
pallet_funding::Call::start_auction { .. } |
pallet_funding::Call::bid { .. } |
pallet_funding::Call::end_auction { .. } |
pallet_funding::Call::contribute { .. } |
Expand Down Expand Up @@ -1023,7 +1022,6 @@ impl pallet_funding::Config for Runtime {
#[cfg(any(test, feature = "runtime-benchmarks", feature = "std"))]
type AllPalletsWithoutSystem =
(Balances, ContributionTokens, ForeignAssets, Oracle, Funding, LinearRelease, Random);
type AuctionInitializePeriodDuration = AuctionInitializePeriodDuration;
type AuctionRoundDuration = AuctionRoundDuration;
type Balance = Balance;
type BlockNumber = BlockNumber;
Expand Down
1 change: 0 additions & 1 deletion runtimes/shared-configuration/src/funding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ pub type ProjectIdentifier = u32;

parameter_types! {
pub const EvaluationRoundDuration: BlockNumber = EVALUATION_ROUND_DURATION;
pub const AuctionInitializePeriodDuration: BlockNumber = AUCTION_INITIALIZE_PERIOD_DURATION;
pub const AuctionRoundDuration: BlockNumber = AUCTION_ROUND_DURATION;
pub const CommunityRoundDuration: BlockNumber = COMMUNITY_ROUND_DURATION;
pub const RemainderRoundDuration: BlockNumber = REMAINDER_ROUND_DURATION;
Expand Down

0 comments on commit aa77143

Please sign in to comment.