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

Take revenue #1228

Merged
merged 7 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions runtime/karura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ use module_evm::{CallInfo, CreateInfo};
use module_evm_accounts::EvmAddressMapping;
use module_evm_manager::EvmCurrencyIdMapping;
use module_transaction_payment::{Multiplier, TargetedFeeAdjustment};
use orml_traits::{create_median_value_data_provider, parameter_type_with_key, DataFeeder, DataProviderExtended};
use orml_traits::{
create_median_value_data_provider, parameter_type_with_key, DataFeeder, DataProviderExtended, MultiCurrency,
};
use pallet_transaction_payment::RuntimeDispatchInfo;

pub use cumulus_primitives_core::ParaId;
Expand All @@ -73,7 +75,7 @@ pub use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, EnsureXcmOrigin,
FixedRateOfConcreteFungible, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, ParentAsSuperuser,
ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit,
};
pub use xcm_executor::{Config, XcmExecutor};

Expand Down Expand Up @@ -1340,6 +1342,19 @@ parameter_types! {

pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom<All<MultiLocation>>);

pub struct ToTreasury;
impl TakeRevenue for ToTreasury {
fn take_revenue(revenue: MultiAsset) {
if let MultiAsset::ConcreteFungible { id, amount } = revenue {
if let Some(currency_id) = CurrencyIdConvert::convert(id) {
// ensure KaruraTreasuryAccount have ed for all of the cross-chain asset.
// Ignore the result.
let _ = Currencies::deposit(currency_id, &KaruraTreasuryAccount::get(), amount);
}
}
}
}

pub struct XcmConfig;
impl Config for XcmConfig {
type Call = Call;
Expand All @@ -1354,8 +1369,7 @@ impl Config for XcmConfig {
type Barrier = Barrier;
type Weigher = FixedWeightBounds<UnitWeightCost, Call>;
// Only receiving KSM is handled, and all fees must be paid in KSM.
//TODO: make treasury take revenue
type Trader = FixedRateOfConcreteFungible<KsmPerSecond, ()>;
type Trader = FixedRateOfConcreteFungible<KsmPerSecond, ToTreasury>;
type ResponseHandler = (); // Don't handle responses for now.
}

Expand Down
22 changes: 18 additions & 4 deletions runtime/mandala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ use module_evm_accounts::EvmAddressMapping;
pub use module_evm_manager::EvmCurrencyIdMapping;
use module_transaction_payment::{Multiplier, TargetedFeeAdjustment};
use orml_tokens::CurrencyAdapter;
use orml_traits::{create_median_value_data_provider, parameter_type_with_key, DataFeeder, DataProviderExtended};
use orml_traits::{
create_median_value_data_provider, parameter_type_with_key, DataFeeder, DataProviderExtended, MultiCurrency,
};
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
use sp_api::impl_runtime_apis;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
Expand Down Expand Up @@ -87,7 +89,7 @@ pub use xcm_builder::{
AccountId32Aliases, AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, EnsureXcmOrigin,
FixedRateOfConcreteFungible, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, ParentAsSuperuser,
ParentIsDefault, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit,
SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeRevenue, TakeWeightCredit,
};
pub use xcm_executor::{Config, XcmExecutor};

Expand Down Expand Up @@ -1641,6 +1643,19 @@ parameter_types! {

pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom<All<MultiLocation>>);

pub struct ToTreasury;
impl TakeRevenue for ToTreasury {
fn take_revenue(revenue: MultiAsset) {
if let MultiAsset::ConcreteFungible { id, amount } = revenue {
if let Some(currency_id) = CurrencyIdConvert::convert(id) {
// ensure KaruraTreasuryAccount have ed for all of the cross-chain asset.
// Ignore the result.
let _ = Currencies::deposit(currency_id, &TreasuryAccount::get(), amount);
}
}
}
}

pub struct XcmConfig;
impl Config for XcmConfig {
type Call = Call;
Expand All @@ -1655,8 +1670,7 @@ impl Config for XcmConfig {
type Barrier = Barrier;
type Weigher = FixedWeightBounds<UnitWeightCost, Call>;
// Only receiving DOT is handled, and all fees must be paid in DOT.
//TODO: make treasury take revenue
type Trader = FixedRateOfConcreteFungible<DotPerSecond, ()>;
type Trader = FixedRateOfConcreteFungible<DotPerSecond, ToTreasury>;
type ResponseHandler = (); // Don't handle responses for now.
}

Expand Down