diff --git a/runtime/src/precompiles/solidity/staking.abi b/runtime/src/precompiles/solidity/staking.abi index c5c6bb38b..82583543d 100644 --- a/runtime/src/precompiles/solidity/staking.abi +++ b/runtime/src/precompiles/solidity/staking.abi @@ -38,9 +38,9 @@ "name": "getStake", "outputs": [ { - "internalType": "uint64", + "internalType": "uint256", "name": "", - "type": "uint64" + "type": "uint256" } ], "stateMutability": "view", diff --git a/runtime/src/precompiles/solidity/staking.sol b/runtime/src/precompiles/solidity/staking.sol index c7efe5a8a..7c80d53e0 100644 --- a/runtime/src/precompiles/solidity/staking.sol +++ b/runtime/src/precompiles/solidity/staking.sol @@ -51,7 +51,7 @@ interface IStaking { * @param hotkey The hotkey public key (32 bytes). * @param coldkey The coldkey public key (32 bytes). * @param netuid The subnet the stake is on (uint256). - * @return The current stake amount in uint64 format. + * @return The current stake amount in uint256 format. */ - function getStake(bytes32 hotkey, bytes32 coldkey, uint256 netuid) external view returns (uint64); + function getStake(bytes32 hotkey, bytes32 coldkey, uint256 netuid) external view returns (uint256); } diff --git a/runtime/src/precompiles/staking.rs b/runtime/src/precompiles/staking.rs index f4439b8a9..bee4b30d1 100644 --- a/runtime/src/precompiles/staking.rs +++ b/runtime/src/precompiles/staking.rs @@ -59,7 +59,7 @@ impl StakingPrecompile { id if id == get_method_id("removeStake(bytes32,uint256,uint256)") => { Self::remove_stake(handle, &method_input) } - id if id == get_method_id("getStake(bytes32,bytes32,uint16)") => { + id if id == get_method_id("getStake(bytes32,bytes32,uint256)") => { Self::get_stake(&method_input) } _ => Err(PrecompileFailure::Error { @@ -112,7 +112,7 @@ impl StakingPrecompile { fn get_stake(data: &[u8]) -> PrecompileResult { let (hotkey, coldkey) = Self::parse_hotkey_coldkey(data)?; - let netuid = Self::parse_netuid(data, 0x3E)?; + let netuid = Self::parse_netuid(data, 0x5E)?; let stake = pallet_subtensor::Pallet::::get_stake_for_hotkey_and_coldkey_on_subnet( &hotkey.into(), @@ -120,9 +120,15 @@ impl StakingPrecompile { netuid, ); + // Convert to EVM decimals let stake_u256 = U256::from(stake); + let stake_eth = + ::BalanceConverter::into_evm_balance(stake_u256) + .ok_or(ExitError::InvalidRange)?; + + // Format output let mut result = [0_u8; 32]; - U256::to_big_endian(&stake_u256, &mut result); + U256::to_big_endian(&stake_eth, &mut result); Ok(PrecompileOutput { exit_status: ExitSucceed::Returned,