Skip to content

Commit

Permalink
refactor: Changed KSM to Relay in INV4
Browse files Browse the repository at this point in the history
  • Loading branch information
arrudagates committed Jan 22, 2024
1 parent acceeea commit bf425e2
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 99 deletions.
10 changes: 5 additions & 5 deletions INV4/pallet-inv4/src/fee_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ use sp_runtime::{
/// Asset to be used by the multisig for paying fees transaction fees.
#[derive(Clone, TypeInfo, Encode, Decode, MaxEncodedLen, Debug, PartialEq, Eq)]
pub enum FeeAsset {
TNKR,
KSM,
Native,
Relay,
}

pub enum FeeAssetNegativeImbalance<TNKRNegativeImbalance, KSMNegativeImbalance> {
TNKR(TNKRNegativeImbalance),
KSM(KSMNegativeImbalance),
pub enum FeeAssetNegativeImbalance<NativeNegativeImbalance, RelayNegativeImbalance> {
Native(NativeNegativeImbalance),
Relay(RelayNegativeImbalance),
}

/// Fee handler trait.
Expand Down
22 changes: 12 additions & 10 deletions INV4/pallet-inv4/src/inv4_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,25 @@ where

// Charge creation fee from the caller
T::FeeCharger::handle_creation_fee(match creation_fee_asset {
FeeAsset::TNKR => {
FeeAssetNegativeImbalance::TNKR(<T as Config>::Currency::withdraw(
FeeAsset::Native => {
FeeAssetNegativeImbalance::Native(<T as Config>::Currency::withdraw(
&creator,
T::CoreCreationFee::get(),
WithdrawReasons::TRANSACTION_PAYMENT,
ExistenceRequirement::KeepAlive,
)?)
}

FeeAsset::KSM => FeeAssetNegativeImbalance::KSM(<T as Config>::Tokens::withdraw(
T::KSMAssetId::get(),
&creator,
T::KSMCoreCreationFee::get(),
Precision::Exact,
Preservation::Protect,
Fortitude::Force,
)?),
FeeAsset::Relay => {
FeeAssetNegativeImbalance::Relay(<T as Config>::Tokens::withdraw(
T::RelayAssetId::get(),
&creator,
T::RelayCoreCreationFee::get(),
Precision::Exact,
Preservation::Protect,
Fortitude::Force,
)?)
}
});

// Update core storages
Expand Down
4 changes: 2 additions & 2 deletions INV4/pallet-inv4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ pub mod pallet {

/// Fee for creating a core in the relay token
#[pallet::constant]
type KSMCoreCreationFee: Get<
type RelayCoreCreationFee: Get<
<<Self as Config>::Tokens as Inspect<<Self as frame_system::Config>::AccountId>>::Balance,
>;

/// Relay token asset id in the runtime
#[pallet::constant]
type KSMAssetId: Get<<<Self as Config>::Tokens as Inspect<<Self as frame_system::Config>::AccountId>>::AssetId>;
type RelayAssetId: Get<<<Self as Config>::Tokens as Inspect<<Self as frame_system::Config>::AccountId>>::AssetId>;

/// Provider of assets functionality for the voting tokens
type AssetsProvider: fungibles::Inspect<Self::AccountId, Balance = BalanceOf<Self>, AssetId = Self::CoreId>
Expand Down
26 changes: 13 additions & 13 deletions INV4/pallet-inv4/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,17 @@ parameter_types! {
243, 115, 218, 162, 0, 9, 138, 232, 68, 55, 129, 106, 210,
]);

pub const KSMCoreCreationFee: Balance = UNIT;
pub const RelayCoreCreationFee: Balance = UNIT;
}

pub type AssetId = u32;

pub const CORE_ASSET_ID: AssetId = 0;
pub const KSM_ASSET_ID: AssetId = 1;
pub const NATIVE_ASSET_ID: AssetId = 0;
pub const RELAY_ASSET_ID: AssetId = 1;

parameter_types! {
pub const NativeAssetId: AssetId = CORE_ASSET_ID;
pub const RelayAssetId: AssetId = KSM_ASSET_ID;
pub const NativeAssetId: AssetId = NATIVE_ASSET_ID;
pub const RelayAssetId: AssetId = RELAY_ASSET_ID;
pub const ExistentialDeposit: u128 = 100000000000;
pub const MaxLocks: u32 = 1;
pub const MaxReserves: u32 = 1;
Expand Down Expand Up @@ -235,7 +235,7 @@ pub type Amount = i128;

orml_traits::parameter_type_with_key! {
pub ExistentialDeposits: |currency_id: AssetId| -> Balance {
if currency_id == &CORE_ASSET_ID {
if currency_id == &RELAY_ASSET_ID {
ExistentialDeposit::get()
} else {
orml_asset_registry::ExistentialDeposits::<Test>::get(currency_id)
Expand Down Expand Up @@ -284,8 +284,8 @@ impl MultisigFeeHandler<Test> for FeeCharger {
who.clone(),
(),
match fee_asset {
FeeAsset::TNKR => None,
FeeAsset::KSM => Some(1u32),
FeeAsset::Native => None,
FeeAsset::Relay => Some(1u32),
},
))
}
Expand Down Expand Up @@ -325,8 +325,8 @@ impl pallet::Config for Test {
type WeightInfo = crate::weights::SubstrateWeight<Test>;

type Tokens = Tokens;
type KSMAssetId = RelayAssetId;
type KSMCoreCreationFee = KSMCoreCreationFee;
type RelayAssetId = RelayAssetId;
type RelayCoreCreationFee = RelayCoreCreationFee;

type MaxCallSize = MaxCallSize;

Expand Down Expand Up @@ -394,9 +394,9 @@ impl ExtBuilder {

orml_tokens::GenesisConfig::<Test> {
balances: vec![
(ALICE, KSM_ASSET_ID, INITIAL_BALANCE),
(BOB, KSM_ASSET_ID, INITIAL_BALANCE),
(CHARLIE, KSM_ASSET_ID, INITIAL_BALANCE),
(ALICE, RELAY_ASSET_ID, INITIAL_BALANCE),
(BOB, RELAY_ASSET_ID, INITIAL_BALANCE),
(CHARLIE, RELAY_ASSET_ID, INITIAL_BALANCE),
],
}
.assimilate_storage(&mut t)
Expand Down
Loading

0 comments on commit bf425e2

Please sign in to comment.