-
Notifications
You must be signed in to change notification settings - Fork 302
Capability to forward tx fees and swap fees to block builder #2426
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
Changes from all commits
2208d29
f6e2f43
bd0d98f
e33246a
3300b1f
280a880
0b346d2
b7ce784
fc31ca5
d1bc5cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ use safe_math::*; | |
| use share_pool::{SharePool, SharePoolDataOperations}; | ||
| use sp_std::ops::Neg; | ||
| use substrate_fixed::types::{I64F64, I96F32, U64F64, U96F32}; | ||
| use subtensor_runtime_common::{AlphaCurrency, Currency, NetUid, TaoCurrency}; | ||
| use subtensor_runtime_common::{AlphaCurrency, AuthorshipInfo, Currency, NetUid, TaoCurrency}; | ||
| use subtensor_swap_interface::{Order, SwapHandler, SwapResult}; | ||
|
|
||
| impl<T: Config> Pallet<T> { | ||
|
|
@@ -590,6 +590,7 @@ impl<T: Config> Pallet<T> { | |
| amount_paid_in: tao, | ||
| amount_paid_out: tao.to_u64().into(), | ||
| fee_paid: TaoCurrency::ZERO, | ||
| fee_to_block_author: TaoCurrency::ZERO, | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -643,19 +644,17 @@ impl<T: Config> Pallet<T> { | |
| amount_paid_in: alpha, | ||
| amount_paid_out: alpha.to_u64().into(), | ||
| fee_paid: AlphaCurrency::ZERO, | ||
| fee_to_block_author: AlphaCurrency::ZERO, | ||
| } | ||
| }; | ||
|
|
||
| // Increase only the protocol Alpha reserve. We only use the sum of | ||
| // (SubnetAlphaIn + SubnetAlphaInProvided) in alpha_reserve(), so it is irrelevant | ||
| // which one to increase. | ||
| // Increase only the protocol Alpha reserve | ||
| let alpha_delta = swap_result.paid_in_reserve_delta_i64().unsigned_abs(); | ||
| SubnetAlphaIn::<T>::mutate(netuid, |total| { | ||
| *total = total.saturating_add(alpha_delta.into()); | ||
| }); | ||
|
|
||
| // Decrease Alpha outstanding. | ||
| // TODO: Deprecate, not accurate in v3 anymore | ||
| SubnetAlphaOut::<T>::mutate(netuid, |total| { | ||
| *total = total.saturating_sub(alpha_delta.into()); | ||
| }); | ||
|
|
@@ -706,6 +705,26 @@ impl<T: Config> Pallet<T> { | |
| Self::increase_stake_for_hotkey_and_coldkey_on_subnet(hotkey, coldkey, netuid, refund); | ||
| } | ||
|
|
||
| // Swap (in a fee-less way) the block builder alpha fee | ||
| let mut fee_outflow = 0_u64; | ||
| let maybe_block_author_coldkey = T::AuthorshipProvider::author(); | ||
| if let Some(block_author_coldkey) = maybe_block_author_coldkey { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, this took me forever to come to the conclusion that it is correct, but it is correct. I would have taken fees on the claim_fees event that the protocol position calls at each block step because then it's super obivous that accounting is correct, but the accounting here is in fact correct. Just took me a long time to realize it. |
||
| let bb_swap_result = Self::swap_alpha_for_tao( | ||
| netuid, | ||
| swap_result.fee_to_block_author, | ||
| T::SwapInterface::min_price::<TaoCurrency>(), | ||
| true, | ||
| )?; | ||
| Self::add_balance_to_coldkey_account( | ||
| &block_author_coldkey, | ||
| bb_swap_result.amount_paid_out.into(), | ||
| ); | ||
| fee_outflow = bb_swap_result.amount_paid_out.into(); | ||
| } else { | ||
| // block author is not found, burn this alpha | ||
| Self::burn_subnet_alpha(netuid, swap_result.fee_to_block_author); | ||
| } | ||
|
|
||
| // If this is a root-stake | ||
| if netuid == NetUid::ROOT { | ||
| // Adjust root claimed value for this hotkey and coldkey. | ||
|
|
@@ -721,7 +740,12 @@ impl<T: Config> Pallet<T> { | |
| // } | ||
|
|
||
| // Record TAO outflow | ||
| Self::record_tao_outflow(netuid, swap_result.amount_paid_out.into()); | ||
| Self::record_tao_outflow( | ||
| netuid, | ||
| swap_result | ||
| .amount_paid_out | ||
| .saturating_add(fee_outflow.into()), | ||
| ); | ||
|
|
||
| LastColdkeyHotkeyStakeBlock::<T>::insert(coldkey, hotkey, Self::get_current_block_as_u64()); | ||
|
|
||
|
|
@@ -797,6 +821,21 @@ impl<T: Config> Pallet<T> { | |
| StakingHotkeys::<T>::insert(coldkey, staking_hotkeys.clone()); | ||
| } | ||
|
|
||
| // Increase the balance of the block author | ||
| let maybe_block_author_coldkey = T::AuthorshipProvider::author(); | ||
| if let Some(block_author_coldkey) = maybe_block_author_coldkey { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. symmetric to alpha case except we don't have to swap back to TAO. |
||
| Self::add_balance_to_coldkey_account( | ||
| &block_author_coldkey, | ||
| swap_result.fee_to_block_author.into(), | ||
| ); | ||
| } else { | ||
| // Block author is not found - burn this TAO | ||
| // Pallet balances total issuance was taken care of when balance was withdrawn for this swap | ||
| TotalIssuance::<T>::mutate(|ti| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: probably should use the burning utils we have. |
||
| *ti = ti.saturating_sub(swap_result.fee_to_block_author); | ||
| }); | ||
| } | ||
|
|
||
| // Record TAO inflow | ||
| Self::record_tao_inflow(netuid, swap_result.amount_paid_in.into()); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
off topic, but this removed comment is still true.