Skip to content

Commit

Permalink
feat: decrease debt
Browse files Browse the repository at this point in the history
  • Loading branch information
mustermeiszer committed Jun 4, 2024
1 parent 4b9e47e commit 401a936
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pallets/loans/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ pub mod pallet {
loan_id: T::LoanId,
amount: PrincipalInput<T>,
},
/// Debt of a loan has been decreased
DebtDecreased {
pool_id: T::PoolId,
loan_id: T::LoanId,
amount: RepaidInput<T>,
},
}

#[pallet::error]
Expand Down Expand Up @@ -890,6 +896,34 @@ pub mod pallet {

Ok(())
}

/// Decrease debt for a loan. Similar to [`Pallet::repay()`] but
/// without transferring from the pool.
///
/// The origin must be the borrower of the loan.
/// The decrease debt action should fulfill the repay restrictions
/// configured at [`types::LoanRestrictions`]. The portfolio valuation
/// of the pool is updated to reflect the new present value of the loan.
#[pallet::weight(T::WeightInfo::increase_debt(T::MaxActiveLoansPerPool::get()))]
#[pallet::call_index(14)]
pub fn decrease_debt(
origin: OriginFor<T>,
pool_id: T::PoolId,
loan_id: T::LoanId,
amount: RepaidInput<T>,
) -> DispatchResult {
let who = ensure_signed(origin)?;

let (amount, _count) = Self::repay_action(&who, pool_id, loan_id, &amount, false)?;

Self::deposit_event(Event::<T>::DebtDecreased {
pool_id,
loan_id,
amount,
});

Ok(())
}
}

// Loan actions
Expand Down

0 comments on commit 401a936

Please sign in to comment.