Skip to content

Commit

Permalink
🐛 Fix Compilation (#364)
Browse files Browse the repository at this point in the history
## What?
- Make the repo compile for a release build and testing

## Why?
- Can't start fixing tests if it won't even compile

## How?
- Remove pallet-sandbox (was pretty old already and not in use)
- Remove old migration code and runtime item
- Add `FundingSuccessThreshold` (33%) to runtime
- Fix basecall filter

## Testing?
- `cargo build --release` and `cargo test` on root folder

## Anything Else?
- Benchmarks still not compiling, will take significant rewrite
  • Loading branch information
JuaniRios authored Aug 23, 2024
1 parent 8b2ca41 commit 80f59b0
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 718 deletions.
23 changes: 0 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pallets/funding/src/functions/3_auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl<T: Config> Pallet<T> {
#[transactional]
pub fn do_end_auction(project_id: ProjectId) -> DispatchResultWithPostInfo {
// * Get variables *
let project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
let project_metadata = ProjectsMetadata::<T>::get(project_id).ok_or(Error::<T>::ProjectMetadataNotFound)?;
let bucket = Buckets::<T>::get(project_id).ok_or(Error::<T>::BucketNotFound)?;

Expand Down
8 changes: 4 additions & 4 deletions pallets/funding/src/functions/6_settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use frame_support::{
dispatch::DispatchResult,
ensure,
traits::{
fungible::MutateHold as FungibleMutateHold,
fungible::{Inspect, MutateHold as FungibleMutateHold},
fungibles::Mutate as FungiblesMutate,
tokens::{Fortitude, Precision, Preservation, Restriction},
tokens::{DepositConsequence, Fortitude, Precision, Preservation, Provenance, Restriction},
Get,
},
};
Expand Down Expand Up @@ -261,8 +261,8 @@ impl<T: Config> Pallet<T> {

let new_plmc_bond = Self::calculate_plmc_bond(new_ticket_size, bid.multiplier)?;
let new_funding_asset_amount = Self::calculate_funding_asset_amount(new_ticket_size, bid.funding_asset)?;
let refund_plmc = bid.plmc_bond.saturating_sub(new_plmc_bond);
let refund_funding_asset = bid.funding_asset_amount_locked.saturating_sub(new_funding_asset_amount);
let mut refund_plmc = bid.plmc_bond.saturating_sub(new_plmc_bond);
let mut refund_funding_asset = bid.funding_asset_amount_locked.saturating_sub(new_funding_asset_amount);
if T::FundingCurrency::can_deposit(
bid.funding_asset.to_assethub_id(),
&bid.bidder,
Expand Down
4 changes: 1 addition & 3 deletions pallets/funding/src/functions/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,7 @@ impl<T: Config> Pallet<T> {
// * Update storage *
ProjectsDetails::<T>::insert(project_id, project_details);

// TODO: FIX event transmition by either doing it outside function or map ProjectStatus
// -> ProjectPhase
// * Emit events *
// // * Emit events *
// Self::deposit_event(Event::ProjectPhaseTransition { project_id, phase: next_round });

Ok(())
Expand Down
23 changes: 8 additions & 15 deletions pallets/funding/src/instantiator/chain_interactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl<
self.execute(|| ProjectsDetails::<T>::get(project_id).expect("Project details exists"))
}

pub fn get_update_block(&mut self, project_id: ProjectId, update_type: &UpdateType) -> Option<BlockNumberFor<T>> {
pub fn get_update_block(&mut self, _project_id: ProjectId, _update_type: &UpdateType) -> Option<BlockNumberFor<T>> {
Some(BlockNumberFor::<T>::zero())
// TODO: FIX
}
Expand All @@ -395,7 +395,6 @@ impl<
issuer: AccountIdOf<T>,
maybe_did: Option<Did>,
) -> ProjectId {
let now = self.current_block();
// one ED for the issuer, one ED for the escrow account
self.mint_plmc_to(vec![UserToPLMCBalance::new(issuer.clone(), self.get_ed() * 2u64.into())]);

Expand All @@ -408,7 +407,7 @@ impl<
});

let created_project_id = self.execute(|| NextProjectId::<T>::get().saturating_sub(One::one()));
self.creation_assertions(created_project_id, maybe_did, project_metadata, now);
self.creation_assertions(created_project_id, maybe_did, project_metadata);
created_project_id
}

Expand Down Expand Up @@ -677,7 +676,7 @@ impl<
pub fn finish_funding(
&mut self,
project_id: ProjectId,
force_decision: Option<FundingOutcomeDecision>,
_force_decision: Option<FundingOutcomeDecision>,
) -> Result<(), DispatchError> {
if let Some(update_block) = self.get_update_block(project_id, &UpdateType::RemainderFundingStart) {
self.execute(|| frame_system::Pallet::<T>::set_block_number(update_block - One::one()));
Expand All @@ -692,13 +691,7 @@ impl<
matches!(project_details.status, ProjectStatus::FundingSuccessful | ProjectStatus::FundingFailed),
"Project should be in Finished status"
);
if project_details.status == ProjectStatus::AwaitingProjectDecision {
if let Some(decision) = force_decision {
self.execute(|| {
crate::Pallet::<T>::do_project_decision(project_id, decision).unwrap();
});
}
}

Ok(())
}

Expand Down Expand Up @@ -1162,10 +1155,10 @@ impl<
remainder_contributions,
),
ProjectStatus::CommunityRound(..) =>
self.create_community_contributing_project(project_metadata, issuer, evaluations, bids),
ProjectStatus::Auction => self.create_auctioning_project(project_metadata, issuer, evaluations),
ProjectStatus::EvaluationRound => self.create_evaluating_project(project_metadata, issuer),
ProjectStatus::Application => self.create_new_project(project_metadata, issuer),
self.create_community_contributing_project(project_metadata, issuer, None, evaluations, bids),
ProjectStatus::Auction => self.create_auctioning_project(project_metadata, issuer, None, evaluations),
ProjectStatus::EvaluationRound => self.create_evaluating_project(project_metadata, issuer, None),
ProjectStatus::Application => self.create_new_project(project_metadata, issuer, None),
_ => panic!("unsupported project creation in that status"),
}
}
Expand Down
156 changes: 1 addition & 155 deletions pallets/funding/src/storage_migrations.rs
Original file line number Diff line number Diff line change
@@ -1,159 +1,5 @@
//! A module that is responsible for migration of storage.
use super::*;
use frame_support::{
pallet_prelude::*,
traits::{tokens::Balance as BalanceT, StorageVersion},
};
use serde::{Deserialize, Serialize};
use frame_support::traits::StorageVersion;
/// The current storage version
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(4);
pub const LOG: &str = "runtime::funding::migration";
use frame_support::traits::OnRuntimeUpgrade;

pub mod v3tov4 {
use super::*;
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
pub struct OldProjectDetails<
AccountId,
Did,
BlockNumber,
Price: FixedPointNumber,
Balance: BalanceT,
EvaluationRoundInfo,
> {
pub issuer_account: AccountId,
pub issuer_did: Did,
/// Whether the project is frozen, so no `metadata` changes are allowed.
pub is_frozen: bool,
/// The price in USD per token decided after the Auction Round
pub weighted_average_price: Option<Price>,
/// The current status of the project
pub status: OldProjectStatus,
/// When the different project phases start and end
pub phase_transition_points: PhaseTransitionPoints<BlockNumber>,
/// Fundraising target amount in USD (6 decimals)
pub fundraising_target_usd: Balance,
/// The amount of Contribution Tokens that have not yet been sold
pub remaining_contribution_tokens: Balance,
/// Funding reached amount in USD (6 decimals)
pub funding_amount_reached_usd: Balance,
/// Information about the total amount bonded, and the outcome in regards to reward/slash/nothing
pub evaluation_round_info: EvaluationRoundInfo,
/// If the auction was oversubscribed, how much USD was raised across all winning bids
pub usd_bid_on_oversubscription: Option<Balance>,
/// When the Funding Round ends
pub funding_end_block: Option<BlockNumber>,
/// ParaId of project
pub parachain_id: Option<ParaId>,
/// Migration readiness check
pub migration_readiness_check: Option<MigrationReadinessCheck>,
/// HRMP Channel status
pub hrmp_channel_status: HRMPChannelStatus,
}

#[derive(Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub struct MigrationReadinessCheck {
pub holding_check: (xcm::v3::QueryId, CheckOutcome),
pub pallet_check: (xcm::v3::QueryId, CheckOutcome),
}

impl MigrationReadinessCheck {
pub fn is_ready(&self) -> bool {
self.holding_check.1 == CheckOutcome::Passed(None) &&
matches!(self.pallet_check.1, CheckOutcome::Passed(Some(_)))
}
}

pub type PalletIndex = u8;
#[derive(Clone, Copy, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
pub enum CheckOutcome {
AwaitingResponse,
Passed(Option<PalletIndex>),
Failed,
}

#[derive(
Default, Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen, Serialize, Deserialize,
)]
pub enum OldProjectStatus {
#[default]
Application,
EvaluationRound,
AuctionInitializePeriod,
AuctionOpening,
AuctionClosing,
CalculatingWAP,
CommunityRound,
RemainderRound,
FundingFailed,
AwaitingProjectDecision,
FundingSuccessful,
ReadyToStartMigration,
MigrationCompleted,
}

type OldProjectDetailsOf<T> =
OldProjectDetails<AccountIdOf<T>, Did, BlockNumberFor<T>, PriceOf<T>, BalanceOf<T>, EvaluationRoundInfoOf<T>>;

pub struct UncheckedMigrationToV4<T: Config>(PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for UncheckedMigrationToV4<T> {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
let mut items = 0;
let mut translate = |_key, item: OldProjectDetailsOf<T>| -> Option<ProjectDetailsOf<T>> {
items += 1;
let new_status = match item.status {
OldProjectStatus::Application => ProjectStatus::Application,
OldProjectStatus::EvaluationRound => ProjectStatus::EvaluationRound,
OldProjectStatus::AuctionInitializePeriod => ProjectStatus::AuctionInitializePeriod,
OldProjectStatus::AuctionOpening => ProjectStatus::AuctionOpening,
OldProjectStatus::AuctionClosing => ProjectStatus::AuctionClosing,
OldProjectStatus::CalculatingWAP => ProjectStatus::CalculatingWAP,
OldProjectStatus::CommunityRound => ProjectStatus::CommunityRound,
OldProjectStatus::RemainderRound => ProjectStatus::RemainderRound,
OldProjectStatus::FundingFailed => ProjectStatus::FundingFailed,
OldProjectStatus::AwaitingProjectDecision => ProjectStatus::AwaitingProjectDecision,
OldProjectStatus::FundingSuccessful => {
debug_assert!(item.funding_end_block.is_none(), "Settlement shouldn't have started yet");
ProjectStatus::FundingSuccessful
},

OldProjectStatus::ReadyToStartMigration => {
debug_assert!(false, "No project should be in this state when upgrading to v4");
ProjectStatus::CTMigrationStarted
},
OldProjectStatus::MigrationCompleted => {
debug_assert!(false, "No project should be in this state when upgrading to v4");
ProjectStatus::CTMigrationFinished
},
};
Some(ProjectDetailsOf::<T> {
issuer_account: item.issuer_account,
issuer_did: item.issuer_did,
is_frozen: item.is_frozen,
weighted_average_price: item.weighted_average_price,
status: new_status,
phase_transition_points: item.phase_transition_points,
fundraising_target_usd: item.fundraising_target_usd,
remaining_contribution_tokens: item.remaining_contribution_tokens,
funding_amount_reached_usd: item.funding_amount_reached_usd,
evaluation_round_info: item.evaluation_round_info,
usd_bid_on_oversubscription: item.usd_bid_on_oversubscription,
funding_end_block: item.funding_end_block,
migration_type: None,
})
};

crate::ProjectsDetails::<T>::translate(|key, object: OldProjectDetailsOf<T>| translate(key, object));

T::DbWeight::get().reads_writes(items, items)
}
}

pub type MigrationToV4<T> = frame_support::migrations::VersionedMigration<
3,
4,
UncheckedMigrationToV4<T>,
crate::Pallet<T>,
<T as frame_system::Config>::DbWeight,
>;
}
2 changes: 1 addition & 1 deletion pallets/funding/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ pub fn create_finished_project_with_usd_raised(
inst.mint_foreign_asset_to(usdt_required);
inst.contribute_for_users(project_id, community_contributions).unwrap();
inst.start_remainder_or_end_funding(project_id).unwrap();
if inst.get_project_details(project_id).status == ProjectStatus::RemainderRound {
if matches!(inst.get_project_details(project_id).status, ProjectStatus::CommunityRound(_)) {
inst.finish_funding(project_id, Some(FundingOutcomeDecision::AcceptFunding)).unwrap();
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/tests/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ fn all_project_participations_by_did() {
let jwt =
get_mock_jwt_with_cid(contribution.contributor, InvestorType::Professional, did_user.clone(), cid.clone());
inst.execute(|| {
PolimecFunding::remaining_contribute(
PolimecFunding::contribute(
RuntimeOrigin::signed(contribution.contributor),
jwt,
project_id,
Expand Down
Loading

0 comments on commit 80f59b0

Please sign in to comment.