Skip to content

Commit

Permalink
Send fees to treasury (#118)
Browse files Browse the repository at this point in the history
* send fees to treasury

* 40% of fees and tips to collators

---------

Co-authored-by: Sergej <[email protected]>
  • Loading branch information
cuteolaf and Szegoo authored May 10, 2024
1 parent 2984525 commit e52b9ee
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
38 changes: 34 additions & 4 deletions runtime/regionx/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@
// You should have received a copy of the GNU General Public License
// along with RegionX. If not, see <https://www.gnu.org/licenses/>.

use crate::{AccountId, AssetId, AssetRegistry, Authorship, Balance, Runtime, RuntimeCall, Tokens};
use crate::{
AccountId, AssetId, AssetRegistry, Authorship, Balance, Balances, PalletCurrency, PotId,
Runtime, RuntimeCall, Tokens, Treasury,
};
use codec::{Decode, Encode, MaxEncodedLen};
use frame_support::traits::{
fungibles, tokens::ConversionToAssetBalance, Defensive, InstanceFilter,
fungibles, tokens::ConversionToAssetBalance, Defensive, Imbalance, InstanceFilter, OnUnbalanced,
};
use orml_asset_registry::DefaultAssetMetadata;
use orml_traits::{asset_registry::AssetProcessor, GetByKey};
use pallet_asset_tx_payment::HandleCredit;
use scale_info::TypeInfo;
use sp_runtime::{
traits::CheckedDiv, ArithmeticError, DispatchError, FixedPointNumber, FixedU128, RuntimeDebug,
TokenError,
traits::{AccountIdConversion, CheckedDiv},
ArithmeticError, DispatchError, FixedPointNumber, FixedU128, RuntimeDebug, TokenError,
};

#[derive(
Expand Down Expand Up @@ -145,3 +148,30 @@ impl GetByKey<AssetId, Balance> for ExistentialDeposits {
}
}
}

type NegativeImbalance = <Balances as PalletCurrency<AccountId>>::NegativeImbalance;

pub struct ToStakingPot;
impl OnUnbalanced<NegativeImbalance> for ToStakingPot {
fn on_nonzero_unbalanced(amount: NegativeImbalance) {
let staking_pot = PotId::get().into_account_truncating();
Balances::resolve_creating(&staking_pot, amount);
}
}

pub struct DealWithFees;
impl OnUnbalanced<NegativeImbalance> for DealWithFees {
fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {
if let Some(fees) = fees_then_tips.next() {
// 60% of the fees go to the treasury, and the rest goes to the collators along with the tips.
let (treasury, mut collators) = fees.ration(60, 40);

if let Some(tips) = fees_then_tips.next() {
tips.merge_into(&mut collators);
}

<ToStakingPot as OnUnbalanced<_>>::on_unbalanced(collators);
Treasury::on_unbalanced(treasury);
}
}
}
5 changes: 2 additions & 3 deletions runtime/regionx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
use frame_support::traits::{
fungible::HoldConsideration,
tokens::{PayFromAccount, UnityAssetBalanceConversion},
EqualPrivilegeOnly, LinearStoragePrice, TransformOrigin,
Currency as PalletCurrency, EqualPrivilegeOnly, LinearStoragePrice, TransformOrigin,
};
use pallet_regions::primitives::StateMachineHeightProvider as StateMachineHeightProviderT;
use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
Expand Down Expand Up @@ -439,8 +439,7 @@ parameter_types! {

impl pallet_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// TODO: send fees to treasury.
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
type OnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;
type WeightToFee = WeightToFee;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
Expand Down

0 comments on commit e52b9ee

Please sign in to comment.