Skip to content

Commit 080363b

Browse files
committed
feat: some func signature changes + hotkey stake
1 parent be2e7a7 commit 080363b

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

runtime/src/precompiles/solidity/staking.abi

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,26 @@
103103
"type": "bytes32"
104104
}
105105
],
106-
"name": "getStakeColdkey",
106+
"name": "getTotalColdkeyStake",
107+
"outputs": [
108+
{
109+
"internalType": "uint256",
110+
"name": "",
111+
"type": "uint256"
112+
}
113+
],
114+
"stateMutability": "view",
115+
"type": "function"
116+
},
117+
{
118+
"inputs": [
119+
{
120+
"internalType": "bytes32",
121+
"name": "hotkey",
122+
"type": "bytes32"
123+
}
124+
],
125+
"name": "getTotalHotkeyStake",
107126
"outputs": [
108127
{
109128
"internalType": "uint256",

runtime/src/precompiles/solidity/staking.sol

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,25 @@ interface IStaking {
4646
* @dev Returns the amount of RAO staked by the coldkey.
4747
*
4848
* This function allows external accounts and contracts to query the amount of RAO staked by the coldkey
49-
* which effectively calls `get_coldkey_stake` on the subtensor pallet with
49+
* which effectively calls `get_total_coldkey_stake` on the subtensor pallet with
5050
* specified coldkey as a parameter.
5151
*
5252
* @param coldkey The coldkey public key (32 bytes).
5353
* @return The amount of RAO staked by the coldkey.
5454
*/
55-
function getStakeColdkey(bytes32 coldkey) external view returns (uint256);
55+
function getTotalColdkeyStake(bytes32 coldkey) external view returns (uint256);
56+
57+
/**
58+
* @dev Returns the total amount of stake under a hotkey (delegative or otherwise)
59+
*
60+
* This function allows external accounts and contracts to query the total amount of RAO staked under a hotkey
61+
* which effectively calls `get_total_hotkey_stake` on the subtensor pallet with
62+
* specified hotkey as a parameter.
63+
*
64+
* @param hotkey The hotkey public key (32 bytes).
65+
* @return The total amount of RAO staked under the hotkey.
66+
*/
67+
function getTotalHotkeyStake(bytes32 hotkey) external view returns (uint256);
5668

5769
/**
5870
* @dev Delegates staking to a proxy account.

runtime/src/precompiles/staking.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ impl StakingPrecompile {
6161
Self::remove_stake(handle, &method_input)
6262
} else if method_id == get_method_id("getStake(bytes32,bytes32,uint256)") {
6363
Self::get_stake(&method_input)
64-
} else if method_id == get_method_id("getStakeColdkey(bytes32)") {
65-
Self::get_stake_coldkey(&method_input)
64+
} else if method_id == get_method_id("getTotalColdkeyStake(bytes32)") {
65+
Self::get_total_coldkey_stake(&method_input)
66+
} else if method_id == get_method_id("getTotalHotkeyStake(bytes32)") {
67+
Self::get_total_hotkey_stake(&method_input)
6668
} else if method_id == get_method_id("addProxy(bytes32)") {
6769
Self::add_proxy(handle, &method_input)
6870
} else if method_id == get_method_id("removeProxy(bytes32)") {
@@ -116,7 +118,7 @@ impl StakingPrecompile {
116118
Self::dispatch(handle, call)
117119
}
118120

119-
fn get_stake_coldkey(data: &[u8]) -> PrecompileResult {
121+
fn get_total_coldkey_stake(data: &[u8]) -> PrecompileResult {
120122
let coldkey: AccountId32 = Self::parse_pub_key(data)?.into();
121123

122124
// get total stake of coldkey
@@ -131,6 +133,21 @@ impl StakingPrecompile {
131133
})
132134
}
133135

136+
fn get_total_hotkey_stake(data: &[u8]) -> PrecompileResult {
137+
let hotkey: AccountId32 = Self::parse_pub_key(data)?.into();
138+
139+
// get total stake of hotkey
140+
let total_stake = pallet_subtensor::Pallet::<Runtime>::get_total_stake_for_hotkey(&hotkey);
141+
let result_u256 = U256::from(total_stake);
142+
let mut result = [0_u8; 32];
143+
U256::to_big_endian(&result_u256, &mut result);
144+
145+
Ok(PrecompileOutput {
146+
exit_status: ExitSucceed::Returned,
147+
output: result.into(),
148+
})
149+
}
150+
134151
fn add_proxy(handle: &mut impl PrecompileHandle, data: &[u8]) -> PrecompileResult {
135152
let delegate = AccountId32::from(Self::parse_pub_key(data)?);
136153
let delegate = <Runtime as frame_system::Config>::Lookup::unlookup(delegate);

0 commit comments

Comments
 (0)