Skip to content

Commit

Permalink
Merge pull request #38 from sander2/fix/slash-to-fee-pool
Browse files Browse the repository at this point in the history
fix: slash issue griefing collateral to fee pool instead of vault
  • Loading branch information
gregdhill authored Mar 18, 2021
2 parents 2c5e6bb + 916de73 commit 0bdee77
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 135 deletions.
4 changes: 4 additions & 0 deletions crates/issue/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ pub(crate) mod fee {
use crate::types::{PolkaBTC, DOT};
use frame_support::dispatch::DispatchError;

pub fn increase_dot_rewards_for_epoch<T: fee::Config>(amount: DOT<T>) {
<fee::Module<T>>::increase_dot_rewards_for_epoch(amount)
}

pub fn fee_pool_account_id<T: fee::Config>() -> T::AccountId {
<fee::Module<T>>::fee_pool_account_id()
}
Expand Down
6 changes: 4 additions & 2 deletions crates/issue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,10 @@ impl<T: Config> Module<T> {
.ok_or(Error::<T>::ArithmeticUnderflow)?;
ext::vault_registry::slash_collateral::<T>(
CurrencySource::Griefing(issue.requester.clone()),
CurrencySource::Backing(issue.vault.clone()),
CurrencySource::FreeBalance(ext::fee::fee_pool_account_id::<T>()),
slashed_collateral,
)?;
ext::fee::increase_dot_rewards_for_epoch::<T>(slashed_collateral);

Self::update_issue_amount(&issue_id, &mut issue, amount_transferred)?;
} else {
Expand Down Expand Up @@ -417,9 +418,10 @@ impl<T: Config> Module<T> {
} else {
ext::vault_registry::slash_collateral::<T>(
CurrencySource::Griefing(issue.requester.clone()),
CurrencySource::Backing(issue.vault.clone()),
CurrencySource::FreeBalance(ext::fee::fee_pool_account_id::<T>()),
issue.griefing_collateral,
)?;
ext::fee::increase_dot_rewards_for_epoch::<T>(issue.griefing_collateral);
}
// Remove issue request from storage
Self::remove_issue_request(issue_id, true);
Expand Down
9 changes: 9 additions & 0 deletions parachain/runtime/tests/mock/issue_testing_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ pub fn execute_issue(issue_id: H256) {
ExecuteIssueBuilder::new(issue_id).assert_execute()
}

pub fn default_user_state() -> UserData {
UserData {
free_balance: DEFAULT_USER_FREE_BALANCE,
locked_balance: DEFAULT_USER_LOCKED_BALANCE,
locked_tokens: DEFAULT_USER_LOCKED_TOKENS,
free_tokens: DEFAULT_USER_FREE_TOKENS,
}
}

pub fn assert_issue_request_event() -> H256 {
let events = SystemModule::events();
let record = events.iter().rev().find(|record| match record.event {
Expand Down
15 changes: 15 additions & 0 deletions parachain/runtime/tests/mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ impl UserData {
}
}

#[derive(Debug, PartialEq, Default)]
pub struct FeePool {
pub balance: u128,
pub tokens: u128,
}

impl FeePool {
pub fn get() -> Self {
Self {
balance: FeeModule::epoch_rewards_dot(),
tokens: FeeModule::epoch_rewards_polka_btc(),
}
}
}

#[derive(Debug, PartialEq, Default)]
pub struct CoreVaultData {
pub to_be_issued: u128,
Expand Down
Loading

0 comments on commit 0bdee77

Please sign in to comment.