Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pallets/loans/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl PoolUpdateGuard for UpdateGuard {
PoolId,
>;
type ScheduledUpdateDetails =
ScheduledUpdateDetails<Rate, MaxTokenNameLength, MaxTokenSymbolLength>;
ScheduledUpdateDetails<Rate, MaxTokenNameLength, MaxTokenSymbolLength, MaxTranches>;

fn released(
_pool: &Self::PoolDetails,
Expand Down Expand Up @@ -307,7 +307,9 @@ impl pallet_interest_accrual::Config for MockRuntime {
}

parameter_types! {
#[derive(Debug, Eq, PartialEq, scale_info::TypeInfo, Clone)]
pub const MaxTranches: u8 = 5;

#[derive(Debug, Eq, PartialEq, scale_info::TypeInfo, Clone)]
pub const MinDelay: Moment = 0;

Expand Down
20 changes: 14 additions & 6 deletions pallets/pools/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,12 @@ fn get_pool<T: Config<PoolId = u64>>() -> PoolDetailsOf<T> {
Pallet::<T>::pool(T::PoolId::from(POOL)).unwrap()
}

fn get_scheduled_update<T: Config<PoolId = u64>>(
) -> ScheduledUpdateDetails<T::InterestRate, T::MaxTokenNameLength, T::MaxTokenSymbolLength> {
fn get_scheduled_update<T: Config<PoolId = u64>>() -> ScheduledUpdateDetails<
Comment thread
lemunozm marked this conversation as resolved.
T::InterestRate,
T::MaxTokenNameLength,
T::MaxTokenSymbolLength,
T::MaxTranches,
> {
Pallet::<T>::scheduled_update(T::PoolId::from(POOL)).unwrap()
}

Expand Down Expand Up @@ -507,14 +511,18 @@ fn create_pool<T: Config<PoolId = u64, Balance = u128, CurrencyId = CurrencyId>>
}

fn build_update_tranche_metadata<T: Config>(
) -> Vec<TrancheMetadata<T::MaxTokenNameLength, T::MaxTokenSymbolLength>> {
) -> BoundedVec<TrancheMetadata<T::MaxTokenNameLength, T::MaxTokenSymbolLength>, T::MaxTranches> {
vec![TrancheMetadata {
token_name: BoundedVec::default(),
token_symbol: BoundedVec::default(),
}]
.try_into()
.expect("T::MaxTranches > 0")
}

fn build_update_tranches<T: Config>(num_tranches: u32) -> Vec<TrancheUpdate<T::InterestRate>> {
fn build_update_tranches<T: Config>(
num_tranches: u32,
) -> BoundedVec<TrancheUpdate<T::InterestRate>, T::MaxTranches> {
let mut tranches = build_bench_update_tranches::<T>(num_tranches);

for tranche in &mut tranches {
Expand All @@ -537,7 +545,7 @@ fn build_update_tranches<T: Config>(num_tranches: u32) -> Vec<TrancheUpdate<T::I

fn build_bench_update_tranches<T: Config>(
num_tranches: u32,
) -> Vec<TrancheUpdate<T::InterestRate>> {
) -> BoundedVec<TrancheUpdate<T::InterestRate>, T::MaxTranches> {
let senior_interest_rate = T::InterestRate::saturating_from_rational(5, 100)
/ T::InterestRate::saturating_from_integer(SECS_PER_YEAR);
let mut tranches: Vec<_> = (1..num_tranches)
Expand All @@ -559,7 +567,7 @@ fn build_bench_update_tranches<T: Config>(
},
);

tranches
tranches.try_into().expect("num_tranches <= T::MaxTranches")
}

fn build_bench_input_tranches<T: Config>(
Expand Down
46 changes: 32 additions & 14 deletions pallets/pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,27 @@ pub struct PoolParameters {
}

#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub struct PoolChanges<Rate, MaxTokenNameLength, MaxTokenSymbolLength>
pub struct PoolChanges<Rate, MaxTokenNameLength, MaxTokenSymbolLength, MaxTranches>
where
MaxTokenNameLength: Get<u32>,
MaxTokenSymbolLength: Get<u32>,
MaxTranches: Get<u32>,
{
pub tranches: Change<Vec<TrancheUpdate<Rate>>>,
pub tranche_metadata: Change<Vec<TrancheMetadata<MaxTokenNameLength, MaxTokenSymbolLength>>>,
pub tranches: Change<BoundedVec<TrancheUpdate<Rate>, MaxTranches>>,
pub tranche_metadata:
Change<BoundedVec<TrancheMetadata<MaxTokenNameLength, MaxTokenSymbolLength>, MaxTranches>>,
pub min_epoch_time: Change<Moment>,
pub max_nav_age: Change<Moment>,
}

#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub struct ScheduledUpdateDetails<Rate, MaxTokenNameLength, MaxTokenSymbolLength>
pub struct ScheduledUpdateDetails<Rate, MaxTokenNameLength, MaxTokenSymbolLength, MaxTranches>
where
MaxTokenNameLength: Get<u32>,
MaxTokenSymbolLength: Get<u32>,
MaxTranches: Get<u32>,
{
pub changes: PoolChanges<Rate, MaxTokenNameLength, MaxTokenSymbolLength>,
pub changes: PoolChanges<Rate, MaxTokenNameLength, MaxTokenSymbolLength, MaxTranches>,
pub scheduled_time: Moment,
}

Expand Down Expand Up @@ -243,6 +246,20 @@ type EpochExecutionInfoOf<T> = EpochExecutionInfo<
type PoolDepositOf<T> =
PoolDepositInfo<<T as frame_system::Config>::AccountId, <T as Config>::Balance>;

type ScheduledUpdateDetailsOf<T> = ScheduledUpdateDetails<
<T as Config>::InterestRate,
<T as Config>::MaxTokenNameLength,
<T as Config>::MaxTokenSymbolLength,
<T as Config>::MaxTranches,
>;

type PoolChangesOf<T> = PoolChanges<
<T as Config>::InterestRate,
<T as Config>::MaxTokenNameLength,
<T as Config>::MaxTokenSymbolLength,
<T as Config>::MaxTranches,
>;

#[frame_support::pallet]
pub mod pallet {
use cfg_traits::PoolUpdateGuard;
Expand Down Expand Up @@ -326,11 +343,7 @@ pub mod pallet {

type UpdateGuard: PoolUpdateGuard<
PoolDetails = PoolDetailsOf<Self>,
ScheduledUpdateDetails = ScheduledUpdateDetails<
Self::InterestRate,
Self::MaxTokenNameLength,
Self::MaxTokenSymbolLength,
>,
ScheduledUpdateDetails = ScheduledUpdateDetailsOf<Self>,
Moment = Moment,
>;

Expand Down Expand Up @@ -402,7 +415,7 @@ pub mod pallet {

/// Max number of Tranches
#[pallet::constant]
type MaxTranches: Get<u32>;
type MaxTranches: Get<u32> + Member + scale_info::TypeInfo;

/// The amount that must be reserved to create a pool
#[pallet::constant]
Expand Down Expand Up @@ -430,7 +443,12 @@ pub mod pallet {
_,
Blake2_128Concat,
T::PoolId,
ScheduledUpdateDetails<T::InterestRate, T::MaxTokenNameLength, T::MaxTokenSymbolLength>,
ScheduledUpdateDetails<
Comment thread
lemunozm marked this conversation as resolved.
T::InterestRate,
T::MaxTokenNameLength,
T::MaxTokenSymbolLength,
T::MaxTranches,
Comment thread
lemunozm marked this conversation as resolved.
>,
>;

#[pallet::storage]
Expand Down Expand Up @@ -780,7 +798,7 @@ pub mod pallet {
pub fn update(
origin: OriginFor<T>,
pool_id: T::PoolId,
changes: PoolChanges<T::InterestRate, T::MaxTokenNameLength, T::MaxTokenSymbolLength>,
changes: PoolChangesOf<T>,
) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
ensure!(
Expand Down Expand Up @@ -1605,7 +1623,7 @@ pub mod pallet {

pub(crate) fn do_update_pool(
pool_id: &T::PoolId,
changes: &PoolChanges<T::InterestRate, T::MaxTokenNameLength, T::MaxTokenSymbolLength>,
changes: &PoolChangesOf<T>,
) -> DispatchResult {
Pool::<T>::try_mutate(pool_id, |pool| -> DispatchResult {
let pool = pool.as_mut().ok_or(Error::<T>::NoSuchPool)?;
Expand Down
4 changes: 3 additions & 1 deletion pallets/pools/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ where

parameter_types! {
pub const PoolPalletId: frame_support::PalletId = cfg_types::ids::POOLS_PALLET_ID;

#[derive(scale_info::TypeInfo, Eq, PartialEq, Debug, Clone, Copy )]
pub const MaxTranches: u32 = 5;

pub const MinUpdateDelay: u64 = 0; // no delay
Expand Down Expand Up @@ -369,7 +371,7 @@ impl PoolUpdateGuard for UpdateGuard {
type PoolDetails =
PoolDetails<CurrencyId, u32, Balance, Rate, MaxSizeMetadata, TrancheWeight, TrancheId, u64>;
type ScheduledUpdateDetails =
ScheduledUpdateDetails<Rate, MaxTokenNameLength, MaxTokenSymbolLength>;
ScheduledUpdateDetails<Rate, MaxTokenNameLength, MaxTokenSymbolLength, MaxTranches>;

fn released(
pool: &Self::PoolDetails,
Expand Down
3 changes: 2 additions & 1 deletion runtime/altair/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ impl pallet_collator_selection::Config for Runtime {
}

parameter_types! {
#[derive(Debug, Eq, PartialEq, scale_info::TypeInfo, Clone)]
pub const MaxTranches: u32 = 5;

// How much time should lapse before a tranche investor can be removed
Expand Down Expand Up @@ -1123,7 +1124,7 @@ impl PoolUpdateGuard for UpdateGuard {
PoolId,
>;
type ScheduledUpdateDetails =
ScheduledUpdateDetails<Rate, MaxTokenNameLength, MaxTokenSymbolLength>;
ScheduledUpdateDetails<Rate, MaxTokenNameLength, MaxTokenSymbolLength, MaxTranches>;

fn released(
pool: &Self::PoolDetails,
Expand Down
3 changes: 2 additions & 1 deletion runtime/development/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ impl PoolUpdateGuard for UpdateGuard {
PoolId,
>;
type ScheduledUpdateDetails =
ScheduledUpdateDetails<Rate, MaxTokenNameLength, MaxTokenSymbolLength>;
ScheduledUpdateDetails<Rate, MaxTokenNameLength, MaxTokenSymbolLength, MaxTranches>;

fn released(
pool: &Self::PoolDetails,
Expand Down Expand Up @@ -1130,6 +1130,7 @@ impl pallet_loans::Config for Runtime {
}

parameter_types! {
#[derive(Debug, Eq, PartialEq, scale_info::TypeInfo, Clone)]
pub const MaxTranches: u32 = 5;

// How much time should lapse before a tranche investor can be removed
Expand Down