diff --git a/src/contract.rs b/src/contract.rs index 52ea7b8..a95d509 100644 --- a/src/contract.rs +++ b/src/contract.rs @@ -125,9 +125,9 @@ pub fn instantiate( BONDS_MOVING_AVERAGE.save(deps.storage, root_netuid, &900_000)?; LAST_ADJUSTMENT_BLOCK.save(deps.storage, root_netuid, &0)?; ADJUSTMENT_INTERVAL.save(deps.storage, root_netuid, &100)?; - BURN.save(deps.storage, root_netuid, &0)?; - MIN_BURN.save(deps.storage, root_netuid, &0)?; - MAX_BURN.save(deps.storage, root_netuid, &1_000_000_000)?; + BURN.save(deps.storage, root_netuid, &1_000_000_000)?; + MIN_BURN.save(deps.storage, root_netuid, &100_000_000)?; + MAX_BURN.save(deps.storage, root_netuid, &100_000_000_000)?; REGISTRATIONS_THIS_BLOCK.save(deps.storage, root_netuid, &0)?; MAX_REGISTRATION_PER_BLOCK.save(deps.storage, root_netuid, &1)?; REGISTRATIONS_THIS_INTERVAL.save(deps.storage, root_netuid, &0)?; @@ -180,9 +180,9 @@ pub fn instantiate( BONDS_MOVING_AVERAGE.save(deps.storage, netuid, &900_000)?; LAST_ADJUSTMENT_BLOCK.save(deps.storage, netuid, &0)?; ADJUSTMENT_INTERVAL.save(deps.storage, netuid, &100)?; - BURN.save(deps.storage, netuid, &0)?; - MIN_BURN.save(deps.storage, netuid, &0)?; - MAX_BURN.save(deps.storage, netuid, &1_000_000_000)?; + BURN.save(deps.storage, netuid, &1_000_000_000)?; + MIN_BURN.save(deps.storage, netuid, &100_000_000)?; + MAX_BURN.save(deps.storage, netuid, &100_000_000_000)?; REGISTRATIONS_THIS_BLOCK.save(deps.storage, netuid, &0)?; MAX_REGISTRATION_PER_BLOCK.save(deps.storage, netuid, &3)?; KAPPA.save(deps.storage, netuid, &32_767)?; @@ -578,6 +578,13 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { QueryMsg::GetAllSubnetNetuids {} => { to_json_binary(&query_all_subnet_netuids(deps.storage)?) }, + QueryMsg::GetNetuidsForHotkey { hotkey } => { + let hotkey_address = deps.api.addr_validate(&hotkey)?; + to_json_binary(&query_netuids_for_hotkey(deps.storage, &hotkey_address)?) + }, + QueryMsg::GetTotalIssuance {} => to_json_binary(&query_total_issuance(deps.storage)?), + QueryMsg::GetTotalStake {} => to_json_binary(&query_total_stake(deps.storage)?), + QueryMsg::GetTxRateLimit {} => to_json_binary(&query_tx_rate_limit(deps.storage)?), // TODO added for debugging, remove later QueryMsg::GetWeights { netuid } => { @@ -725,6 +732,27 @@ pub fn query_all_subnet_netuids(store: &dyn Storage) -> StdResult> { Ok(netuids) } +pub fn query_netuids_for_hotkey(store: &dyn Storage, hotkey: &Addr) -> StdResult> { + let networks = get_registered_networks_for_hotkey(store, hotkey); + + Ok(networks) +} + +pub fn query_total_issuance(store: &dyn Storage) -> StdResult { + let issuance = TOTAL_ISSUANCE.load(store)?; + Ok(issuance) +} + +pub fn query_total_stake(store: &dyn Storage) -> StdResult { + let stake = TOTAL_STAKE.load(store)?; + Ok(stake) +} + +pub fn query_tx_rate_limit(store: &dyn Storage) -> StdResult { + let limit = TX_RATE_LIMIT.load(store)?; + Ok(limit) +} + #[cfg_attr(not(feature = "library"), entry_point)] pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { let storage_version: ContractVersion = get_contract_version(deps.storage)?; diff --git a/src/msg.rs b/src/msg.rs index b5ae286..5bb2df3 100644 --- a/src/msg.rs +++ b/src/msg.rs @@ -267,6 +267,9 @@ pub enum QueryMsg { #[returns(Option)] GetUidForHotkeyOnSubnet { hotkey: String, netuid: u16 }, + #[returns(Option>)] + GetNetuidsForHotkey { hotkey: String }, + #[returns(bool)] GetSubnetExist { netuid: u16 }, @@ -300,6 +303,15 @@ pub enum QueryMsg { #[returns(Vec)] GetAllSubnetNetuids {}, + #[returns(u64)] + GetTotalIssuance {}, + + #[returns(u64)] + GetTotalStake {}, + + #[returns(u64)] + GetTxRateLimit {}, + // TODO added for debugging, remove later #[returns(Vec>)] GetWeights { netuid: u16 }, diff --git a/src/registration.rs b/src/registration.rs index 672d423..14c74e6 100644 --- a/src/registration.rs +++ b/src/registration.rs @@ -440,17 +440,17 @@ pub fn do_registration( ); // --- 8. Ensure the supplied work passes the difficulty. - // let difficulty = get_difficulty(deps.storage, netuid); - // let work_hash: H256 = vec_to_hash(work.clone()); - // ensure!( - // hash_meets_difficulty(&work_hash, difficulty), - // ContractError::InvalidDifficulty {} - // ); // Check that the work meets difficulty. + let difficulty = get_difficulty(deps.storage, netuid); + let work_hash: H256 = vec_to_hash(work.clone()); + ensure!( + hash_meets_difficulty(&work_hash, difficulty), + ContractError::InvalidDifficulty {} + ); // Check that the work meets difficulty. // --- 7. Check Work is the product of the nonce, the block number, and hotkey. Add this as used work. - // let seal: H256 = create_seal_hash(block_number, nonce, hotkey.as_str()); - // ensure!(seal == work_hash, ContractError::InvalidSeal {}); - // USED_WORK.save(deps.storage, work.clone(), ¤t_block_number)?; + let seal: H256 = create_seal_hash(block_number, nonce, hotkey.as_str()); + ensure!(seal == work_hash, ContractError::InvalidSeal {}); + USED_WORK.save(deps.storage, work.clone(), ¤t_block_number)?; // --- 9. If the network account does not exist we will create it here. create_account_if_non_existent(deps.storage, &coldkey, &hotkey);