Skip to content

Commit a9aeda2

Browse files
committed
Add flow for inflation adjustment. Multiple actions allowed at a time for different projects. Fix 196
1 parent 1b42541 commit a9aeda2

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

pallets/proxy-financial/src/functions.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ impl<T: Config> Pallet<T> {
141141
image,
142142
address,
143143
status: ProjectStatus::default(),
144+
inflation_rate: None,
144145
registration_date: timestamp,
145146
creation_date,
146147
completion_date,
@@ -840,7 +841,7 @@ impl<T: Config> Pallet<T> {
840841
project_id: [u8;32],
841842
drawdown_id: [u8;32],
842843
) -> DispatchResult {
843-
//TODO: Ensure builder permissions
844+
//TODO: Ensure builder & admin permissions
844845

845846
// Ensure project exists & is not completed
846847
Self::is_project_completed(project_id)?;
@@ -1245,6 +1246,51 @@ impl<T: Config> Pallet<T> {
12451246
Ok(())
12461247
}
12471248

1249+
// I N F L A T I O N A D J U S T M E N T
1250+
// --------------------------------------------------------------------------------------------
1251+
pub fn do_execute_inflation_adjustment(
1252+
admin: T::AccountId,
1253+
projects: BoundedVec<([u8;32], Option<u32>, CUDAction), T::MaxRegistrationsAtTime>,
1254+
) -> DispatchResult {
1255+
// Ensure admin permissions
1256+
Self::is_superuser(admin.clone(), &Self::get_global_scope(), ProxyRole::Administrator.id())?;
1257+
1258+
// Ensure projects is not empty
1259+
ensure!(!projects.is_empty(), Error::<T>::ProjectsIsEmpty);
1260+
1261+
// Match each CUD action
1262+
for project in projects {
1263+
// Ensure project exists
1264+
ensure!(ProjectsInfo::<T>::contains_key(project.0), Error::<T>::ProjectNotFound);
1265+
match project.2 {
1266+
// Delete need: project_id
1267+
CUDAction::Delete => {
1268+
// Mutate project data
1269+
<ProjectsInfo<T>>::try_mutate::<_,_,DispatchError,_>(project.0, |project_info| {
1270+
let mod_project_data = project_info.as_mut().ok_or(Error::<T>::ProjectNotFound)?;
1271+
mod_project_data.inflation_rate = None;
1272+
Ok(())
1273+
})?;
1274+
},
1275+
// Creation & Update need: project_id, inflation_rate
1276+
_ => {
1277+
// Mutate project data
1278+
1279+
// Ensure inflation rate is provided
1280+
let inflation_rate = project.1.ok_or(Error::<T>::InflationRateRequired)?;
1281+
1282+
<ProjectsInfo<T>>::try_mutate::<_,_,DispatchError,_>(project.0, |project_info| {
1283+
let mod_project_data = project_info.as_mut().ok_or(Error::<T>::ProjectNotFound)?;
1284+
mod_project_data.inflation_rate = Some(inflation_rate);
1285+
Ok(())
1286+
})?;
1287+
},
1288+
}
1289+
}
1290+
1291+
Ok(())
1292+
}
1293+
12481294
// H E L P E R S
12491295
// --------------------------------------------------------------------------------------------
12501296

pallets/proxy-financial/src/lib.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,10 @@ pub mod pallet {
441441
BulkUpdateIsRequired,
442442
/// NO feedback for EN5 drawdown was provided
443443
EB5FeebackMissing,
444+
/// Inflation rate extrinsic is missing an array of changes
445+
ProjectsIsEmpty,
446+
/// Inflation rate was not provided
447+
InflationRateRequired,
444448

445449
}
446450

@@ -676,8 +680,6 @@ pub mod pallet {
676680

677681
// Do submit drawdown
678682
Self::do_submit_drawdown(who, project_id, drawdown_id)
679-
// - ensure drawdown has transactions
680-
//ensure!(TransactionsByDrawdown::<T>::contains_key(project_id, drawdown_id), Error::<T>::NoTransactionsToSubmit);
681683
},
682684
}
683685

@@ -790,6 +792,21 @@ pub mod pallet {
790792
Self::do_up_bulk_upload(who, project_id, drawdown_id, description, total_amount, documents)
791793
}
792794

795+
/// Modify inflation rate
796+
///
797+
/// projects: project_id, inflation_rate, CUDAction
798+
#[transactional]
799+
#[pallet::weight(10_000 + T::DbWeight::get().writes(1))]
800+
pub fn inflation_rate(
801+
origin: OriginFor<T>,
802+
projects: BoundedVec<([u8;32], Option<u32>, CUDAction), T::MaxRegistrationsAtTime>,
803+
) -> DispatchResult {
804+
let who = ensure_signed(origin)?; // origin need to be a builder
805+
806+
Self::do_execute_inflation_adjustment(who, projects)
807+
}
808+
809+
793810
/// Kill all the stored data.
794811
///
795812
/// This function is used to kill ALL the stored data.
@@ -822,8 +839,6 @@ pub mod pallet {
822839
Ok(())
823840
}
824841

825-
826-
827842
// /// Testing extrinsic
828843
// #[transactional]
829844
// #[pallet::weight(10_000 + T::DbWeight::get().writes(1))]

0 commit comments

Comments
 (0)