Skip to content

Commit

Permalink
Added total rewards field to economy data query
Browse files Browse the repository at this point in the history
  • Loading branch information
cyborgshead committed May 23, 2024
1 parent ee9daa2 commit f95ffc3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
4 changes: 4 additions & 0 deletions schema/cybernet.json
Original file line number Diff line number Diff line change
Expand Up @@ -3044,6 +3044,7 @@
"default_commission",
"staker_apr",
"total_issuance",
"total_rewards",
"total_stake",
"validator_apr"
],
Expand All @@ -3063,6 +3064,9 @@
"total_issuance": {
"$ref": "#/definitions/Coin"
},
"total_rewards": {
"$ref": "#/definitions/Coin"
},
"total_stake": {
"$ref": "#/definitions/Coin"
},
Expand Down
4 changes: 4 additions & 0 deletions schema/raw/response_to_get_economy.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"default_commission",
"staker_apr",
"total_issuance",
"total_rewards",
"total_stake",
"validator_apr"
],
Expand All @@ -27,6 +28,9 @@
"total_issuance": {
"$ref": "#/definitions/Coin"
},
"total_rewards": {
"$ref": "#/definitions/Coin"
},
"total_stake": {
"$ref": "#/definitions/Coin"
},
Expand Down
22 changes: 5 additions & 17 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)))
Expand All @@ -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,
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 8 additions & 2 deletions src/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub const ROOT: Item<Addr> = Item::new("root");
pub const COMMISSION_CHANGE: Item<bool> = Item::new("commission_switch");
pub const DENOM: Item<String> = Item::new("denom");
pub const VERSE_METADATA: Item<Metadata> = Item::new("verse_metadata");
pub const TOTAL_REWARDS: Item<u64> = Item::new("total_rewards");

// ============================
// ==== Staking + Accounts ====
Expand Down

0 comments on commit f95ffc3

Please sign in to comment.