Skip to content

Commit dfbed6b

Browse files
authored
Merge pull request opentensor#907 from opentensor/evm-stake-netuid
feat: add evm stake netuid parameter
2 parents 6136f7b + 514af7f commit dfbed6b

File tree

3 files changed

+52
-39
lines changed

3 files changed

+52
-39
lines changed

runtime/src/precompiles/solidity/staking.abi

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
"internalType": "bytes32",
66
"name": "hotkey",
77
"type": "bytes32"
8+
},
9+
{
10+
"internalType": "uint16",
11+
"name": "netuid",
12+
"type": "uint16"
813
}
914
],
1015
"name": "addStake",
@@ -23,11 +28,16 @@
2328
"internalType": "uint256",
2429
"name": "amount",
2530
"type": "uint256"
31+
},
32+
{
33+
"internalType": "uint16",
34+
"name": "netuid",
35+
"type": "uint16"
2636
}
2737
],
2838
"name": "removeStake",
2939
"outputs": [],
3040
"stateMutability": "payable",
3141
"type": "function"
3242
}
33-
]
43+
]

runtime/src/precompiles/solidity/staking.sol

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,43 @@ pragma solidity ^0.8.0;
33
address constant ISTAKING_ADDRESS = 0x0000000000000000000000000000000000000801;
44

55
interface IStaking {
6-
/**
7-
* @dev Adds a subtensor stake corresponding to the value sent with the transaction, associated
8-
* with the `hotkey`.
9-
*
10-
* This function allows external accounts and contracts to stake TAO into the subtensor pallet,
11-
* which effectively calls `add_stake` on the subtensor pallet with specified hotkey as a parameter
12-
* and coldkey being the hashed address mapping of H160 sender address to Substrate ss58 address as
13-
* implemented in Frontier HashedAddressMapping:
14-
* https://github.com/polkadot-evm/frontier/blob/2e219e17a526125da003e64ef22ec037917083fa/frame/evm/src/lib.rs#L739
15-
*
16-
* @param hotkey The hotkey public key (32 bytes).
17-
*
18-
* Requirements:
19-
* - `hotkey` must be a valid hotkey registered on the network, ensuring that the stake is
20-
* correctly attributed.
21-
*/
22-
function addStake(bytes32 hotkey) external payable;
6+
/**
7+
* @dev Adds a subtensor stake corresponding to the value sent with the transaction, associated
8+
* with the `hotkey`.
9+
*
10+
* This function allows external accounts and contracts to stake TAO into the subtensor pallet,
11+
* which effectively calls `add_stake` on the subtensor pallet with specified hotkey as a parameter
12+
* and coldkey being the hashed address mapping of H160 sender address to Substrate ss58 address as
13+
* implemented in Frontier HashedAddressMapping:
14+
* https://github.com/polkadot-evm/frontier/blob/2e219e17a526125da003e64ef22ec037917083fa/frame/evm/src/lib.rs#L739
15+
*
16+
* @param hotkey The hotkey public key (32 bytes).
17+
* @param netuid The subnet to stake to (uint16). Currently a noop, functionality will be enabled with RAO.
18+
*
19+
* Requirements:
20+
* - `hotkey` must be a valid hotkey registered on the network, ensuring that the stake is
21+
* correctly attributed.
22+
*/
23+
function addStake(bytes32 hotkey, uint16 netuid) external payable;
2324

24-
/**
25-
* @dev Removes a subtensor stake `amount` from the specified `hotkey`.
26-
*
27-
* This function allows external accounts and contracts to unstake TAO from the subtensor pallet,
28-
* which effectively calls `remove_stake` on the subtensor pallet with specified hotkey as a parameter
29-
* and coldkey being the hashed address mapping of H160 sender address to Substrate ss58 address as
30-
* implemented in Frontier HashedAddressMapping:
31-
* https://github.com/polkadot-evm/frontier/blob/2e219e17a526125da003e64ef22ec037917083fa/frame/evm/src/lib.rs#L739
32-
*
33-
* @param hotkey The hotkey public key (32 bytes).
34-
* @param amount The amount to unstake in rao.
35-
*
36-
* Requirements:
37-
* - `hotkey` must be a valid hotkey registered on the network, ensuring that the stake is
38-
* correctly attributed.
39-
* - The existing stake amount must be not lower than specified amount
40-
*/
41-
function removeStake(bytes32 hotkey, uint256 amount) external;
42-
}
25+
/**
26+
* @dev Removes a subtensor stake `amount` from the specified `hotkey`.
27+
*
28+
* This function allows external accounts and contracts to unstake TAO from the subtensor pallet,
29+
* which effectively calls `remove_stake` on the subtensor pallet with specified hotkey as a parameter
30+
* and coldkey being the hashed address mapping of H160 sender address to Substrate ss58 address as
31+
* implemented in Frontier HashedAddressMapping:
32+
* https://github.com/polkadot-evm/frontier/blob/2e219e17a526125da003e64ef22ec037917083fa/frame/evm/src/lib.rs#L739
33+
*
34+
* @param hotkey The hotkey public key (32 bytes).
35+
* @param amount The amount to unstake in rao.
36+
* @param netuid The subnet to stake to (uint16). Currently a noop, functionality will be enabled with RAO.
37+
38+
*
39+
* Requirements:
40+
* - `hotkey` must be a valid hotkey registered on the network, ensuring that the stake is
41+
* correctly attributed.
42+
* - The existing stake amount must be not lower than specified amount
43+
*/
44+
function removeStake(bytes32 hotkey, uint256 amount, uint16 netuid) external;
45+
}

runtime/src/precompiles/staking.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ impl StakingPrecompile {
5353
.map_or_else(vec::Vec::new, |slice| slice.to_vec()); // Avoiding borrowing conflicts
5454

5555
match method_id {
56-
id if id == get_method_id("addStake(bytes32)") => {
56+
id if id == get_method_id("addStake(bytes32,uint16)") => {
5757
Self::add_stake(handle, &method_input)
5858
}
59-
id if id == get_method_id("removeStake(bytes32,uint256)") => {
59+
id if id == get_method_id("removeStake(bytes32,uint256,uint16)") => {
6060
Self::remove_stake(handle, &method_input)
6161
}
6262
_ => Err(PrecompileFailure::Error {

0 commit comments

Comments
 (0)