diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index a8774795b9..11ca6d6d03 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -228,7 +228,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 244, + spec_version: 245, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, diff --git a/runtime/src/precompiles/solidity/staking.abi b/runtime/src/precompiles/solidity/staking.abi index 3c4a018c90..f06dfb651b 100644 --- a/runtime/src/precompiles/solidity/staking.abi +++ b/runtime/src/precompiles/solidity/staking.abi @@ -94,5 +94,43 @@ "outputs": [], "stateMutability": "nonpayable", "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "coldkey", + "type": "bytes32" + } + ], + "name": "getTotalColdkeyStake", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "hotkey", + "type": "bytes32" + } + ], + "name": "getTotalHotkeyStake", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" } ] \ No newline at end of file diff --git a/runtime/src/precompiles/solidity/staking.sol b/runtime/src/precompiles/solidity/staking.sol index 19d51d0470..4666183700 100644 --- a/runtime/src/precompiles/solidity/staking.sol +++ b/runtime/src/precompiles/solidity/staking.sol @@ -46,12 +46,36 @@ interface IStaking { uint256 netuid ) external; - /** - * @dev Delegates staking to a proxy account. - * - * @param delegate The public key (32 bytes) of the delegate. - */ - function addProxy(bytes32 delegate) external; + /** + * @dev Returns the amount of RAO staked by the coldkey. + * + * This function allows external accounts and contracts to query the amount of RAO staked by the coldkey + * which effectively calls `get_total_coldkey_stake` on the subtensor pallet with + * specified coldkey as a parameter. + * + * @param coldkey The coldkey public key (32 bytes). + * @return The amount of RAO staked by the coldkey. + */ + function getTotalColdkeyStake(bytes32 coldkey) external view returns (uint256); + + /** + * @dev Returns the total amount of stake under a hotkey (delegative or otherwise) + * + * This function allows external accounts and contracts to query the total amount of RAO staked under a hotkey + * which effectively calls `get_total_hotkey_stake` on the subtensor pallet with + * specified hotkey as a parameter. + * + * @param hotkey The hotkey public key (32 bytes). + * @return The total amount of RAO staked under the hotkey. + */ + function getTotalHotkeyStake(bytes32 hotkey) external view returns (uint256); + + /** + * @dev Delegates staking to a proxy account. + * + * @param delegate The public key (32 bytes) of the delegate. + */ + function addProxy(bytes32 delegate) external; /** * @dev Removes staking proxy account. diff --git a/runtime/src/precompiles/staking.rs b/runtime/src/precompiles/staking.rs index 848fe8e750..51e8382598 100644 --- a/runtime/src/precompiles/staking.rs +++ b/runtime/src/precompiles/staking.rs @@ -90,6 +90,43 @@ impl StakingPrecompile { handle.try_dispatch_runtime_call(call, RawOrigin::Signed(account_id)) } + #[precompile::public("getTotalColdkeyStake(bytes32)")] + fn get_total_coldkey_stake( + _handle: &mut impl PrecompileHandle, + coldkey_h256: H256, + ) -> EvmResult { + let (coldkey, _) = parse_pubkey(coldkey_h256.as_bytes())?; + + // get total stake of coldkey + let total_stake = + pallet_subtensor::Pallet::::get_total_stake_for_coldkey(&coldkey); + // Convert to EVM decimals + let stake_u256 = U256::from(total_stake); + let stake_eth = + ::BalanceConverter::into_evm_balance(stake_u256) + .ok_or(ExitError::InvalidRange)?; + + Ok(stake_eth) + } + + #[precompile::public("getTotalHotkeyStake(bytes32)")] + fn get_total_hotkey_stake( + _handle: &mut impl PrecompileHandle, + hotkey_h256: H256, + ) -> EvmResult { + let (hotkey, _) = parse_pubkey(hotkey_h256.as_bytes())?; + + // get total stake of hotkey + let total_stake = pallet_subtensor::Pallet::::get_total_stake_for_hotkey(&hotkey); + // Convert to EVM decimals + let stake_u256 = U256::from(total_stake); + let stake_eth = + ::BalanceConverter::into_evm_balance(stake_u256) + .ok_or(ExitError::InvalidRange)?; + + Ok(stake_eth) + } + #[precompile::public("addProxy(bytes32)")] fn add_proxy(handle: &mut impl PrecompileHandle, delegate: H256) -> EvmResult<()> { let account_id = handle.caller_account_id();