diff --git a/schema/cybernet.json b/schema/cybernet.json index 8d98b2d..ec7c581 100644 --- a/schema/cybernet.json +++ b/schema/cybernet.json @@ -3044,6 +3044,7 @@ "default_commission", "staker_apr", "total_issuance", + "total_rewards", "total_stake", "validator_apr" ], @@ -3063,6 +3064,9 @@ "total_issuance": { "$ref": "#/definitions/Coin" }, + "total_rewards": { + "$ref": "#/definitions/Coin" + }, "total_stake": { "$ref": "#/definitions/Coin" }, diff --git a/schema/raw/response_to_get_economy.json b/schema/raw/response_to_get_economy.json index ffbe2d3..bffa1b1 100644 --- a/schema/raw/response_to_get_economy.json +++ b/schema/raw/response_to_get_economy.json @@ -8,6 +8,7 @@ "default_commission", "staker_apr", "total_issuance", + "total_rewards", "total_stake", "validator_apr" ], @@ -27,6 +28,9 @@ "total_issuance": { "$ref": "#/definitions/Coin" }, + "total_rewards": { + "$ref": "#/definitions/Coin" + }, "total_stake": { "$ref": "#/definitions/Coin" }, diff --git a/src/contract.rs b/src/contract.rs index 82ed564..0b25b87 100644 --- a/src/contract.rs +++ b/src/contract.rs @@ -18,23 +18,7 @@ use crate::root::{do_root_register, get_network_lock_cost, user_add_network, use use crate::serving::{do_serve_axon, do_serve_prometheus}; use crate::stake_info::{get_stake_info_for_coldkey, get_stake_info_for_coldkeys}; use crate::staking::{do_add_stake, do_become_delegate, do_remove_stake, do_set_delegate_commission}; -use crate::state::{ - ACTIVE, ACTIVITY_CUTOFF, ADJUSTMENT_INTERVAL, ADJUSTMENTS_ALPHA, ALLOW_FAUCET, AxonInfo, AXONS, - BLOCK_EMISSION, BLOCKS_SINCE_LAST_STEP, BONDS_MOVING_AVERAGE, BURN, BURN_REGISTRATIONS_THIS_INTERVAL, COMMISSION_CHANGE, - CONSENSUS, DEFAULT_TAKE, DELEGATES, DENOM, DIFFICULTY, DIVIDENDS, - EMISSION, EMISSION_VALUES, IMMUNITY_PERIOD, INCENTIVE, KAPPA, LAST_ADJUSTMENT_BLOCK, LAST_UPDATE, - MAX_ALLOWED_UIDS, MAX_ALLOWED_VALIDATORS, MAX_BURN, MAX_DIFFICULTY, MAX_REGISTRATION_PER_BLOCK, - MAX_WEIGHTS_LIMIT, Metadata, METADATA, MIN_ALLOWED_WEIGHTS, MIN_BURN, MIN_DIFFICULTY, - NETWORK_IMMUNITY_PERIOD, NETWORK_LAST_LOCK_COST, NETWORK_LAST_REGISTERED, NETWORK_LOCK_REDUCTION_INTERVAL, - NETWORK_MIN_LOCK_COST, NETWORK_MODALITY, NETWORK_RATE_LIMIT, - NETWORK_REGISTERED_AT, NETWORK_REGISTRATION_ALLOWED, NETWORKS_ADDED, NETWORKS_METADATA, - OWNER, PENDING_EMISSION, POW_REGISTRATIONS_THIS_INTERVAL, PROMETHEUS, PrometheusInfo, PRUNING_SCORES, - RANK, RAO_RECYCLED_FOR_REGISTRATION, REGISTRATIONS_THIS_BLOCK, REGISTRATIONS_THIS_INTERVAL, - RHO, ROOT, SERVING_RATE_LIMIT, STAKE, SUBNET_LIMIT, SUBNET_LOCKED, SUBNET_OWNER, - SUBNET_OWNER_CUT, SUBNETWORK_N, TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, - TOTAL_COLDKEY_STAKE, TOTAL_HOTKEY_STAKE, TOTAL_ISSUANCE, TOTAL_NETWORKS, TOTAL_STAKE, TRUST, TX_RATE_LIMIT, - UIDS, VALIDATOR_PERMIT, VALIDATOR_TRUST, VERSE_METADATA, WEIGHTS_SET_RATE_LIMIT, WEIGHTS_VERSION_KEY -}; +use crate::state::{ACTIVE, ACTIVITY_CUTOFF, ADJUSTMENT_INTERVAL, ADJUSTMENTS_ALPHA, ALLOW_FAUCET, AxonInfo, AXONS, BLOCK_EMISSION, BLOCKS_SINCE_LAST_STEP, BONDS_MOVING_AVERAGE, BURN, BURN_REGISTRATIONS_THIS_INTERVAL, COMMISSION_CHANGE, CONSENSUS, DEFAULT_TAKE, DELEGATES, DENOM, DIFFICULTY, DIVIDENDS, EMISSION, EMISSION_VALUES, IMMUNITY_PERIOD, INCENTIVE, KAPPA, LAST_ADJUSTMENT_BLOCK, LAST_UPDATE, MAX_ALLOWED_UIDS, MAX_ALLOWED_VALIDATORS, MAX_BURN, MAX_DIFFICULTY, MAX_REGISTRATION_PER_BLOCK, MAX_WEIGHTS_LIMIT, Metadata, METADATA, MIN_ALLOWED_WEIGHTS, MIN_BURN, MIN_DIFFICULTY, NETWORK_IMMUNITY_PERIOD, NETWORK_LAST_LOCK_COST, NETWORK_LAST_REGISTERED, NETWORK_LOCK_REDUCTION_INTERVAL, NETWORK_MIN_LOCK_COST, NETWORK_MODALITY, NETWORK_RATE_LIMIT, NETWORK_REGISTERED_AT, NETWORK_REGISTRATION_ALLOWED, NETWORKS_ADDED, NETWORKS_METADATA, OWNER, PENDING_EMISSION, POW_REGISTRATIONS_THIS_INTERVAL, PROMETHEUS, PrometheusInfo, PRUNING_SCORES, RANK, RAO_RECYCLED_FOR_REGISTRATION, REGISTRATIONS_THIS_BLOCK, REGISTRATIONS_THIS_INTERVAL, RHO, ROOT, SERVING_RATE_LIMIT, STAKE, SUBNET_LIMIT, SUBNET_LOCKED, SUBNET_OWNER, SUBNET_OWNER_CUT, SUBNETWORK_N, TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, TOTAL_COLDKEY_STAKE, TOTAL_HOTKEY_STAKE, TOTAL_ISSUANCE, TOTAL_NETWORKS, TOTAL_REWARDS, TOTAL_STAKE, TRUST, TX_RATE_LIMIT, UIDS, VALIDATOR_PERMIT, VALIDATOR_TRUST, VERSE_METADATA, WEIGHTS_SET_RATE_LIMIT, WEIGHTS_VERSION_KEY}; use crate::state_info::get_state_info; use crate::subnet_info::{get_subnet_hyperparams, get_subnet_info, get_subnets_info}; use crate::uids::get_registered_networks_for_hotkey; @@ -988,6 +972,7 @@ pub fn get_economy( let commission_change = COMMISSION_CHANGE.load(store)?; let blocks_per_year = 5256000u64; let total_issuance = TOTAL_ISSUANCE.load(store)?; + let total_rewards = TOTAL_REWARDS.load(store)?; let validator_apr = Decimal::new(Uint128::from(block_rewards).mul(Uint128::from(blocks_per_year))) .div(Decimal::new(Uint128::from(total_stake))) @@ -999,6 +984,8 @@ pub fn get_economy( .mul(Decimal::from_atomics(Uint128::from(100u64),0).unwrap()); + let total_rewards = Coin::new(u128::from(total_rewards), denom.clone()); + let economy_data = EconomyData{ validator_apr, staker_apr, @@ -1007,6 +994,7 @@ pub fn get_economy( default_commission, commission_change, total_issuance: Coin::new(u128::from(total_issuance), denom), + total_rewards }; Ok(economy_data) diff --git a/src/msg.rs b/src/msg.rs index bf3c6d7..6b6acd4 100644 --- a/src/msg.rs +++ b/src/msg.rs @@ -361,6 +361,7 @@ pub struct EconomyData { pub default_commission: Decimal, pub commission_change: bool, pub total_issuance: Coin, + pub total_rewards: Coin, } #[cw_serde] diff --git a/src/root.rs b/src/root.rs index fe3a7ba..6a5fd5e 100644 --- a/src/root.rs +++ b/src/root.rs @@ -23,7 +23,7 @@ use crate::state::{ RAO_RECYCLED_FOR_REGISTRATION, REGISTRATIONS_THIS_BLOCK, REGISTRATIONS_THIS_INTERVAL, RHO, SERVING_RATE_LIMIT, SUBNETWORK_N, SUBNET_LIMIT, SUBNET_OWNER, TARGET_REGISTRATIONS_PER_INTERVAL, TEMPO, TOTAL_NETWORKS, TRUST, UIDS, VALIDATOR_PERMIT, - VALIDATOR_TRUST, WEIGHTS, WEIGHTS_SET_RATE_LIMIT, WEIGHTS_VERSION_KEY, + VALIDATOR_TRUST, WEIGHTS, WEIGHTS_SET_RATE_LIMIT, WEIGHTS_VERSION_KEY, TOTAL_REWARDS, }; use crate::uids::{append_neuron, get_hotkey_for_net_and_uid, get_subnetwork_n, replace_neuron}; use crate::utils::{ @@ -309,7 +309,13 @@ pub fn root_epoch( // --- 4. Determines the total block emission across all the subnetworks. This is the // value which will be distributed based on the computation below. - let block_emission: I64F64 = I64F64::from_num(get_block_emission(store)); + let block_emission_u64: u64 = get_block_emission(store); + let block_emission: I64F64 = I64F64::from_num(block_emission_u64); + TOTAL_REWARDS.update(store, |val| -> StdResult<_> { + let mut amount = val; + amount += block_emission_u64; + Ok(amount) + })?; api.debug(&format!("🔵 block_emission: {:?}", block_emission)); // --- 5. A collection of all registered hotkeys on the root network. Hotkeys diff --git a/src/state.rs b/src/state.rs index cc161c2..a1156ce 100644 --- a/src/state.rs +++ b/src/state.rs @@ -10,6 +10,7 @@ pub const ROOT: Item = Item::new("root"); pub const COMMISSION_CHANGE: Item = Item::new("commission_switch"); pub const DENOM: Item = Item::new("denom"); pub const VERSE_METADATA: Item = Item::new("verse_metadata"); +pub const TOTAL_REWARDS: Item = Item::new("total_rewards"); // ============================ // ==== Staking + Accounts ====