Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(asset-index): move redemption fee to storage #443

Merged
merged 9 commits into from
Oct 29, 2021
1 change: 1 addition & 0 deletions runtime/common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK;
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;
pub const WEEKS: BlockNumber = DAYS * 7;

// Unit = the base number of indivisible units for balances
pub const UNIT: Balance = 1_000_000_000_000;
Expand Down
17 changes: 17 additions & 0 deletions runtime/common/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2021 ChainSafe Systems
// SPDX-License-Identifier: LGPL-3.0-only
use crate::constants::DAYS;
use primitives::{Balance, BlockNumber};
use sp_std::marker::PhantomData;

/// Origin either `Root` or `CommitteeOrigin`
Expand Down Expand Up @@ -37,3 +39,18 @@ impl<T: frame_system::Config> pallet_asset_index::traits::LockupPeriodRange<T::B
(crate::constants::DAYS * 28).into()
}
}

/// Redemption fee
pub struct RedemptionFee;

impl primitives::traits::RedemptionFee<BlockNumber, Balance> for RedemptionFee {
fn redemption_fee(time_spent: BlockNumber, amount: Balance) -> Balance {
if time_spent < 7 * DAYS {
amount.checked_div(10).unwrap_or_default()
} else if time_spent < 30 * DAYS {
amount.checked_div(20).unwrap_or_default()
} else {
amount.checked_div(100).unwrap_or_default()
}
clearloop marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 1 addition & 1 deletion runtime/dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ impl pallet_asset_index::Config for Runtime {
type Balance = Balance;
type MaxActiveDeposits = MaxActiveDeposits;
type MaxDecimals = MaxDecimals;
type RedemptionFee = ();
type RedemptionFee = RedemptionFee;
type LockupPeriod = LockupPeriodDev;
type LockupPeriodRange = LockupPeriodRangeDev<Self>;
type IndexTokenLockIdentifier = IndexTokenLockIdentifier;
Expand Down
2 changes: 1 addition & 1 deletion runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ impl pallet_asset_index::Config for Runtime {
type Balance = Balance;
type MaxActiveDeposits = MaxActiveDeposits;
type MaxDecimals = MaxDecimals;
type RedemptionFee = ();
type RedemptionFee = RedemptionFee;
type LockupPeriod = LockupPeriod;
type LockupPeriodRange = LockupPeriodRange<Self>;
type IndexTokenLockIdentifier = IndexTokenLockIdentifier;
Expand Down
2 changes: 1 addition & 1 deletion runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ impl pallet_asset_index::Config for Runtime {
type Balance = Balance;
type MaxActiveDeposits = MaxActiveDeposits;
type MaxDecimals = MaxDecimals;
type RedemptionFee = ();
type RedemptionFee = RedemptionFee;
type LockupPeriod = LockupPeriod;
type LockupPeriodRange = LockupPeriodRange<Self>;
type IndexTokenLockIdentifier = IndexTokenLockIdentifier;
Expand Down