-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1859 from subspace/tx-fee
Collect the domain transaction fee and use as the operator reward
- Loading branch information
Showing
13 changed files
with
389 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[package] | ||
name = "pallet-operator-rewards" | ||
version = "0.1.0" | ||
authors = ["Subspace Labs <https://subspace.network>"] | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
homepage = "https://subspace.network" | ||
repository = "https://github.com/subspace/subspace" | ||
description = "Subspace node pallet for charging and re-distributing domain transaction fees" | ||
include = [ | ||
"/src", | ||
"/Cargo.toml", | ||
] | ||
|
||
[dependencies] | ||
codec = { package = "parity-scale-codec", version = "3.6.3", default-features = false, features = ["derive"] } | ||
frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" } | ||
frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" } | ||
scale-info = { version = "2.7.0", default-features = false, features = ["derive"] } | ||
sp-runtime = { version = "24.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" } | ||
sp-std = { version = "8.0.0", default-features = false, git = "https://github.com/subspace/substrate", rev = "55c157cff49b638a59d81a9f971f0f9a66829c71" } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"codec/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"scale-info/std", | ||
"sp-runtime/std", | ||
"sp-std/std", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (C) 2023 Subspace Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//! Pallet Domain Transaction Fees | ||
|
||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
pub use pallet::*; | ||
|
||
#[frame_support::pallet] | ||
mod pallet { | ||
use codec::{Codec, MaxEncodedLen}; | ||
use frame_support::pallet_prelude::*; | ||
use frame_system::pallet_prelude::*; | ||
use scale_info::TypeInfo; | ||
use sp_runtime::traits::{AtLeast32BitUnsigned, MaybeSerializeDeserialize, Saturating, Zero}; | ||
use sp_runtime::FixedPointOperand; | ||
use sp_std::fmt::Debug; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config { | ||
/// The balance of an account. | ||
type Balance: Parameter | ||
+ Member | ||
+ AtLeast32BitUnsigned | ||
+ Codec | ||
+ Default | ||
+ Copy | ||
+ MaybeSerializeDeserialize | ||
+ Debug | ||
+ MaxEncodedLen | ||
+ TypeInfo | ||
+ FixedPointOperand; | ||
} | ||
|
||
/// The accumulated rewards of the current block | ||
/// | ||
/// Currently, the only source of rewards is the transaction fees, in the furture it | ||
/// will include the XDM reward. | ||
#[pallet::storage] | ||
#[pallet::getter(fn block_transaction_fee)] | ||
pub(super) type BlockRewards<T: Config> = StorageValue<_, T::Balance, ValueQuery>; | ||
|
||
/// Pallet operator-rewards to store the accumulated rewards of the current block | ||
#[pallet::pallet] | ||
#[pallet::without_storage_info] | ||
pub struct Pallet<T>(_); | ||
|
||
#[pallet::hooks] | ||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> { | ||
fn on_initialize(_now: BlockNumberFor<T>) -> Weight { | ||
BlockRewards::<T>::set(Zero::zero()); | ||
T::DbWeight::get().writes(1) | ||
} | ||
} | ||
|
||
impl<T: Config> Pallet<T> { | ||
pub fn note_transaction_fees(tx_fee: T::Balance) { | ||
let next_block_rewards = BlockRewards::<T>::get().saturating_add(tx_fee); | ||
BlockRewards::<T>::set(next_block_rewards); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.