Skip to content

Commit 66151f4

Browse files
committed
fix: added comments.
1 parent 20dbbd1 commit 66151f4

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

crates/issue/src/lib.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,46 +305,63 @@ impl<T: Config> Pallet<T> {
305305
T::TreasuryPalletId::get().into_account_truncating()
306306
}
307307

308+
// Function to cancel an issue request and slash collateral
308309
pub fn cancel_issue_request_and_slash_collateral(issue_id: &H256) -> Result<BalanceOf<T>, DispatchError> {
310+
// Get the issue request using the provided issue_id
309311
let issue = Self::get_issue_request_from_id(issue_id)?;
310312

313+
// Retrieve the amount of griefing collateral from the issue
311314
let griefing_collateral = issue.griefing_collateral();
312315

316+
// Transfer griefing collateral from the requester's account to the vault's account
313317
ext::vault_registry::transfer_funds::<T>(
314318
CurrencySource::UserGriefing(issue.requester.get_account().clone()),
315319
CurrencySource::FreeBalance(issue.vault.account_id),
316320
&griefing_collateral,
317321
)?;
318322

323+
// Set the status of the issue request to 'Cancelled'
319324
Self::set_issue_status(issue_id.clone(), IssueRequestStatus::Cancelled);
320325

326+
// Emit an event to indicate the cancellation of the issue request
321327
Self::deposit_event(Event::CancelIssue {
322328
issue_id: issue_id.clone(),
323329
requester: issue.requester.get_account().clone(),
324330
griefing_collateral: griefing_collateral.amount(),
325331
});
326332

333+
// Return the amount of griefing collateral that was slashed
327334
Ok(griefing_collateral.amount())
328335
}
329336

337+
// Function to retrieve the vault ID associated with a given issue ID
330338
pub fn get_vault_from_id_from_issue_id(issue_id: &H256) -> Result<DefaultVaultId<T>, DispatchError> {
339+
// Retrieve the issue request using the provided issue_id
331340
let issue_request = Self::get_issue_request_from_id(issue_id)?;
341+
342+
// Extract and return the associated vault ID from the issue request
332343
Ok(issue_request.vault)
333344
}
334345

346+
// Function to complete a vault issue process
335347
pub fn _complete_vault_issue(issue_id: H256) -> Result<(), DispatchError> {
348+
// Retrieve the issue request using the provided issue_id
336349
let issue = Self::get_issue_request_from_id(&issue_id)?;
350+
351+
// Calculate the total amount including both issue amount and fee
337352
let total = issue.amount().checked_add(&issue.fee())?;
338-
// issue_tokens -> decrease to_be_issued & increase issued for new vault
353+
354+
// Decrease the to-be-issued tokens and increase the issued tokens for the new vault
339355
ext::vault_registry::issue_tokens::<T>(&issue.vault, &total)?;
340356

341-
// distribute rewards
357+
// Distribute rewards based on the issue fee
342358
ext::fee::distribute_rewards::<T>(&issue.fee())?;
343359

344-
// release griefing collateral
360+
// Release the locked griefing collateral to the requester's account
345361
let griefing_collateral: Amount<T> = issue.griefing_collateral();
346362
griefing_collateral.unlock_on(&issue.requester.get_account())?;
347363

364+
// Set the issue status to 'Completed'
348365
Self::set_issue_status(issue_id, IssueRequestStatus::Completed);
349366

350367
Ok(())

crates/redeem/src/lib.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,20 @@ pub mod pallet {
404404
Ok(().into())
405405
}
406406

407+
/// Request a replace operation for a vault
408+
///
409+
/// ## Parameters
410+
///
411+
/// - `origin`: The origin from which the request is made, typically the vault owner.
412+
/// - `currency_pair`: The trading pair associated with the collateral and backing assets.
413+
/// - `amount`: The amount of backed asset to be replaced.
414+
/// - `new_vault_id`: The identifier of the new vault that will replace the existing vault.
415+
/// - `griefing_currency`: The currency in which a griefing deposit is required for the replace.
416+
///
417+
/// ## Returns
418+
///
419+
/// If the replace operation is successful, this function returns `Ok`. If the operation fails,
420+
/// an appropriate error indicating the reason for failure is returned.
407421
#[pallet::call_index(7)]
408422
#[pallet::weight(<T as Config>::WeightInfo::request_replace())]
409423
#[transactional]
@@ -845,6 +859,8 @@ impl<T: Config> Pallet<T> {
845859
Ok(())
846860
}
847861

862+
// Cancels a redeem request, replaces it with a new issue request, adjusts vault balances, and
863+
// updates the system state.
848864
fn _cancel_replace_request(redeem_id: H256, issue_id: H256) -> DispatchResult {
849865
let redeem = Self::get_open_redeem_request_from_id(&redeem_id)?;
850866

@@ -868,7 +884,7 @@ impl<T: Config> Pallet<T> {
868884
// cancel issue request and slash collateral
869885
let slashed_amount = ext::issue::cancel_issue_request_and_slash_collateral::<T>(&issue_id)?;
870886

871-
// cancel redeem request
887+
// Set the status of the redeem request to "Cancelled"
872888
Self::set_redeem_status(redeem_id, RedeemRequestStatus::Cancelled);
873889

874890
// release event

parachain/runtime/runtime-tests/src/parachain/fee_pool.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,9 +1014,7 @@ fn accrued_lend_token_interest_increases_reward_share() {
10141014
}
10151015
activate_lending_and_mint(Token(DOT), LendToken(1));
10161016
let vault_id = PrimitiveVaultId::new(account_of(VAULT), LendToken(1), DEFAULT_WRAPPED_CURRENCY);
1017-
println!(" \n---- 1 ---- ");
10181017
CoreVaultData::force_to(&vault_id, default_vault_state(&vault_id));
1019-
println!(" \n---- 2 ---- ");
10201018

10211019
// Borrow some lend_tokens so interest starts accruing in the market
10221020
let initial_lend_token_stake: u128 = CapacityRewardsPallet::get_stake(&(), &vault_id.collateral_currency()).unwrap();

0 commit comments

Comments
 (0)