Skip to content

Commit f4ffb5c

Browse files
committed
Fix get_stake in staking precompile
1 parent af7a541 commit f4ffb5c

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

runtime/src/precompiles/solidity/staking.abi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
"name": "getStake",
3939
"outputs": [
4040
{
41-
"internalType": "uint64",
41+
"internalType": "uint256",
4242
"name": "",
43-
"type": "uint64"
43+
"type": "uint256"
4444
}
4545
],
4646
"stateMutability": "view",

runtime/src/precompiles/solidity/staking.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ interface IStaking {
5151
* @param hotkey The hotkey public key (32 bytes).
5252
* @param coldkey The coldkey public key (32 bytes).
5353
* @param netuid The subnet the stake is on (uint256).
54-
* @return The current stake amount in uint64 format.
54+
* @return The current stake amount in uint256 format.
5555
*/
56-
function getStake(bytes32 hotkey, bytes32 coldkey, uint256 netuid) external view returns (uint64);
56+
function getStake(bytes32 hotkey, bytes32 coldkey, uint256 netuid) external view returns (uint256);
5757
}

runtime/src/precompiles/staking.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl StakingPrecompile {
5959
id if id == get_method_id("removeStake(bytes32,uint256,uint256)") => {
6060
Self::remove_stake(handle, &method_input)
6161
}
62-
id if id == get_method_id("getStake(bytes32,bytes32,uint16)") => {
62+
id if id == get_method_id("getStake(bytes32,bytes32,uint256)") => {
6363
Self::get_stake(&method_input)
6464
}
6565
_ => Err(PrecompileFailure::Error {
@@ -112,17 +112,23 @@ impl StakingPrecompile {
112112

113113
fn get_stake(data: &[u8]) -> PrecompileResult {
114114
let (hotkey, coldkey) = Self::parse_hotkey_coldkey(data)?;
115-
let netuid = Self::parse_netuid(data, 0x3E)?;
115+
let netuid = Self::parse_netuid(data, 0x5E)?;
116116

117117
let stake = pallet_subtensor::Pallet::<Runtime>::get_stake_for_hotkey_and_coldkey_on_subnet(
118118
&hotkey.into(),
119119
&coldkey.into(),
120120
netuid,
121121
);
122122

123+
// Convert to EVM decimals
123124
let stake_u256 = U256::from(stake);
125+
let stake_eth =
126+
<Runtime as pallet_evm::Config>::BalanceConverter::into_evm_balance(stake_u256)
127+
.ok_or(ExitError::InvalidRange)?;
128+
129+
// Format output
124130
let mut result = [0_u8; 32];
125-
U256::to_big_endian(&stake_u256, &mut result);
131+
U256::to_big_endian(&stake_eth, &mut result);
126132

127133
Ok(PrecompileOutput {
128134
exit_status: ExitSucceed::Returned,

0 commit comments

Comments
 (0)