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

[TASK] Define collator rewards and inflation strategy #26

Closed
1xstj opened this issue Jun 16, 2022 · 1 comment · Fixed by #29
Closed

[TASK] Define collator rewards and inflation strategy #26

1xstj opened this issue Jun 16, 2022 · 1 comment · Fixed by #29
Assignees
Labels
difficulty: medium 🚩 feature ➕ Tasks that are functional additions or enhancements p1 🟠

Comments

@1xstj
Copy link
Contributor

1xstj commented Jun 16, 2022

Inflationary rewards

We want to allocate a fraction of genesis tokens to collators over a 2 year period as well as define a mechanism for inflationary rewards once this amount of tokens runs out.

We’d like to target 1-5% inflation for

  • collators
  • treasury

Desired Outcome

  • Every block payout
  • The pallet account will receive an amount of tokens at genesis
  • These tokens will be distributed at configured RewardAmount to the collators (block author)
  • Once the genesis amount of tokens are depleted, the pallet will create new tokens
  • New amount of tokens created every block according to inflation rate

Docs

@1xstj 1xstj self-assigned this Jun 16, 2022
@1xstj
Copy link
Contributor Author

1xstj commented Jun 16, 2022

Example Implementation

Create a new pallet reward-handler. The pallet will

  • implement OnUnbalanced to accept the block_reward + tips
  • calculate the amount of tokens to transfer based on inflation rate
  • transfer block_reward + tips + new_tokens to block_author every block (or part to treasury)

Pallet Config

/// The pallet's configuration trait.
pub trait Config: frame_system::Config + pallet_balances::Config + pallet_treasury::Config {
	/// The overarching event type.
	type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;

	/// The amount of tokens to mint every block
	type RewardAmount: Get<Self::Balance>;

        /// PalletAccount
	type PalletAccount: Get<Self::AccountId>;
}

OnUnbalanced Handler

pub struct DealWithFees<R>(sp_std::marker::PhantomData<R>);
impl<R> OnUnbalanced<NegativeImbalance<R>> for DealWithFees<R>
{
	fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance<R>>) {
		if let Some(fees) = fees_then_tips.next() {
			// for fees, 80% to treasury, 20% to author
			// We could also make this configurable
			let mut split = fees.ration(80, 20);
			if let Some(tips) = fees_then_tips.next() {
				// for tips, if any, 100% to author
				tips.merge_into(&mut split.1);
			}

                         // try to pay the collator reward amount from the pallet account
                         if Balances::can_transfer() {
                                  let block_author_reward = split.1 + Balances::withdraw(PalletAccount::get())
                         }
                         // if cannot pay from pallet account then add inlfation amount
                        else  {
                              // create new tokens
                              Balances::issue(T::RewardAmount::get())
                              let block_author_reward = split.1 + T::RewardAmount::get();
                         }

			<Treasury<R> as OnUnbalanced<_>>::on_unbalanced(split.0);
			<ToAuthor<R> as OnUnbalanced<_>>::on_unbalanced(block_author_reward);
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: medium 🚩 feature ➕ Tasks that are functional additions or enhancements p1 🟠
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants