Skip to content

Commit

Permalink
pallet funding OTM integration
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed Sep 23, 2024
1 parent 70655e3 commit 0cce953
Show file tree
Hide file tree
Showing 31 changed files with 695 additions and 298 deletions.
38 changes: 20 additions & 18 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pallet-parachain-staking = { path = "pallets/parachain-staking", default-feature
pallet-linear-release = { path = "pallets/linear-release", default-features = false }
polimec-receiver = { path = "pallets/polimec-receiver", default-features = false }
on-slash-vesting = { path = "pallets/on-slash-vesting", default-features = false }
pallet-proxy-bonding = { path = "pallets/proxy-bonding", default-features = false }

# Internal macros
macros = { path = "macros" }
Expand Down
4 changes: 4 additions & 0 deletions pallets/funding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ variant_count = "1.1.0"

pallet-linear-release.workspace = true
on-slash-vesting.workspace = true
pallet-proxy-bonding.workspace = true

# Substrate dependencies
frame-support.workspace = true
Expand Down Expand Up @@ -95,6 +96,7 @@ std = [
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
"pallet-proxy-bonding/std"
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand All @@ -115,6 +117,7 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"pallet-proxy-bonding/runtime-benchmarks"
]
try-runtime = [
"frame-support/try-runtime",
Expand All @@ -128,5 +131,6 @@ try-runtime = [
"polimec-common-test-utils?/try-runtime",
"polimec-common/try-runtime",
"sp-runtime/try-runtime",
"pallet-proxy-bonding/try-runtime"
]
on-chain-release-build = []
24 changes: 14 additions & 10 deletions pallets/funding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,11 +1040,15 @@ mod benchmarks {

let price = inst.get_project_details(project_id).weighted_average_price.unwrap();

let contributions =
vec![
ContributionParams::new(contributor.clone(), (50 * CT_UNIT).into(), 1u8, AcceptedFundingAsset::USDT);
x as usize + 1
];
let contributions = vec![
ContributionParams::new(
contributor.clone(),
(50 * CT_UNIT).into(),
ParticipationMode::Classic(1u8),
AcceptedFundingAsset::USDT
);
x as usize + 1
];

let plmc = inst.calculate_contributed_plmc_spent(contributions.clone(), price, false);
let usdt = inst.calculate_contributed_funding_asset_spent(contributions.clone(), price);
Expand Down Expand Up @@ -1078,7 +1082,7 @@ mod benchmarks {
jwt,
project_id,
contributions[0].amount,
contributions[0].multiplier,
contributions[0].mode,
contributions[0].asset,
);

Expand Down Expand Up @@ -1112,7 +1116,7 @@ mod benchmarks {
funding_asset: AcceptedFundingAsset::USDT,
funding_amount: usdt[0].asset_amount,
plmc_bond: plmc[0].plmc_amount,
multiplier: contributions[0].multiplier,
mode: contributions[0].mode,
}
.into(),
);
Expand Down Expand Up @@ -1504,7 +1508,7 @@ mod benchmarks {
ContributionParams::<T>::new(
participant.clone(),
(10 * CT_UNIT).into(),
1u8,
ParticipationMode::Classic(1),
AcceptedFundingAsset::USDT,
)
})
Expand Down Expand Up @@ -1846,7 +1850,7 @@ mod benchmarks {
ContributionParams::<T>::new(
participant.clone(),
(10 * CT_UNIT).into(),
1u8,
ParticipationMode::Classic(1),
AcceptedFundingAsset::USDT,
)
})
Expand Down Expand Up @@ -1937,7 +1941,7 @@ mod benchmarks {
ContributionParams::<T>::new(
participant.clone(),
(10 * CT_UNIT).into(),
1u8,
ParticipationMode::Classic(1),
AcceptedFundingAsset::USDT,
)
})
Expand Down
5 changes: 3 additions & 2 deletions pallets/funding/src/functions/2_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ impl<T: Config> Pallet<T> {
let mut project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
let now = <frame_system::Pallet<T>>::block_number();
let evaluation_id = NextEvaluationId::<T>::get();
let plmc_usd_price = T::PriceProvider::get_decimals_aware_price(PLMC_FOREIGN_ID, USD_DECIMALS, PLMC_DECIMALS)
.ok_or(Error::<T>::PriceNotFound)?;
let plmc_usd_price =
<PriceProviderOf<T>>::get_decimals_aware_price(PLMC_FOREIGN_ID, USD_DECIMALS, PLMC_DECIMALS)
.ok_or(Error::<T>::PriceNotFound)?;
let early_evaluation_reward_threshold_usd =
T::EvaluationSuccessThreshold::get() * project_details.fundraising_target_usd;
let evaluation_round_info = &mut project_details.evaluation_round_info;
Expand Down
23 changes: 8 additions & 15 deletions pallets/funding/src/functions/3_auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,8 @@ impl<T: Config> Pallet<T> {
#[transactional]
pub fn do_bid(params: DoBidParams<T>) -> DispatchResultWithPostInfo {
// * Get variables *
let DoBidParams {
bidder,
project_id,
ct_amount,
multiplier,
funding_asset,
investor_type,
did,
whitelisted_policy,
} = params;
let DoBidParams { bidder, project_id, ct_amount, mode, funding_asset, investor_type, did, whitelisted_policy } =
params;
let project_metadata = ProjectsMetadata::<T>::get(project_id).ok_or(Error::<T>::ProjectMetadataNotFound)?;
let project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;

Expand Down Expand Up @@ -120,7 +112,7 @@ impl<T: Config> Pallet<T> {
metadata_ticket_size_bounds.usd_ticket_above_minimum_per_participation(min_total_ticket_size),
Error::<T>::TooLow
);
ensure!(multiplier.into() <= max_multiplier && multiplier.into() > 0u8, Error::<T>::ForbiddenMultiplier);
ensure!(mode.multiplier() <= max_multiplier && mode.multiplier() > 0u8, Error::<T>::ForbiddenMultiplier);

// Note: We limit the CT Amount to the auction allocation size, to avoid long-running loops.
ensure!(
Expand All @@ -145,7 +137,7 @@ impl<T: Config> Pallet<T> {
project_id,
ct_amount,
ct_usd_price: current_bucket.current_price,
multiplier,
mode,
funding_asset,
bid_id,
now,
Expand Down Expand Up @@ -179,7 +171,7 @@ impl<T: Config> Pallet<T> {
project_id,
ct_amount,
ct_usd_price,
multiplier,
mode,
funding_asset,
bid_id,
now,
Expand All @@ -191,6 +183,7 @@ impl<T: Config> Pallet<T> {

let ticket_size = ct_usd_price.checked_mul_int(ct_amount).ok_or(Error::<T>::BadMath)?;
let total_usd_bid_by_did = AuctionBoughtUSD::<T>::get((project_id, did.clone()));
let multiplier: MultiplierOf<T> = mode.multiplier().try_into().map_err(|_| Error::<T>::BadMath)?;

ensure!(
metadata_ticket_size_bounds
Expand All @@ -214,12 +207,12 @@ impl<T: Config> Pallet<T> {
original_ct_usd_price: ct_usd_price,
funding_asset,
funding_asset_amount_locked,
multiplier,
mode,
plmc_bond,
when: now,
};

Self::try_plmc_participation_lock(&bidder, project_id, plmc_bond)?;
Self::bond_plmc_with_mode(&bidder, project_id, plmc_bond, mode, funding_asset)?;
Self::try_funding_asset_hold(&bidder, project_id, funding_asset_amount_locked, funding_asset.id())?;

Bids::<T>::insert((project_id, bidder.clone(), bid_id), &new_bid);
Expand Down
13 changes: 7 additions & 6 deletions pallets/funding/src/functions/4_contribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl<T: Config> Pallet<T> {
contributor,
project_id,
ct_amount: token_amount,
multiplier,
mode,
funding_asset,
investor_type,
did,
Expand Down Expand Up @@ -48,7 +48,7 @@ impl<T: Config> Pallet<T> {
project_id,
project_details: &mut project_details,
buyable_tokens,
multiplier,
mode,
funding_asset,
investor_type,
did,
Expand All @@ -65,7 +65,7 @@ impl<T: Config> Pallet<T> {
project_id,
project_details,
buyable_tokens,
multiplier,
mode,
funding_asset,
investor_type,
did,
Expand All @@ -91,6 +91,7 @@ impl<T: Config> Pallet<T> {
InvestorType::Professional => PROFESSIONAL_MAX_MULTIPLIER,
InvestorType::Institutional => INSTITUTIONAL_MAX_MULTIPLIER,
};
let multiplier: MultiplierOf<T> = mode.multiplier().try_into().map_err(|_| Error::<T>::ForbiddenMultiplier)?;

// * Validity checks *
ensure!(project_policy == whitelisted_policy, Error::<T>::PolicyMismatch);
Expand Down Expand Up @@ -125,15 +126,15 @@ impl<T: Config> Pallet<T> {
contributor: contributor.clone(),
ct_amount: buyable_tokens,
usd_contribution_amount: ticket_size,
multiplier,
mode: mode.clone(),
funding_asset,
funding_asset_amount,
plmc_bond,
when: now,
};

// Try adding the new contribution to the system
Self::try_plmc_participation_lock(&contributor, project_id, plmc_bond)?;
Self::bond_plmc_with_mode(&contributor, project_id, plmc_bond, mode, funding_asset)?;
Self::try_funding_asset_hold(&contributor, project_id, funding_asset_amount, funding_asset.id())?;

Contributions::<T>::insert((project_id, contributor.clone(), contribution_id), &new_contribution);
Expand All @@ -152,7 +153,7 @@ impl<T: Config> Pallet<T> {
funding_asset,
funding_amount: funding_asset_amount,
plmc_bond,
multiplier,
mode,
});

// return correct weight function
Expand Down
Loading

0 comments on commit 0cce953

Please sign in to comment.