Skip to content

Commit

Permalink
netuid stake parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
orriin committed Nov 1, 2024
1 parent 70f4c63 commit 514af7f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 39 deletions.
12 changes: 11 additions & 1 deletion runtime/src/precompiles/solidity/staking.abi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"internalType": "bytes32",
"name": "hotkey",
"type": "bytes32"
},
{
"internalType": "uint16",
"name": "netuid",
"type": "uint16"
}
],
"name": "addStake",
Expand All @@ -23,11 +28,16 @@
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "uint16",
"name": "netuid",
"type": "uint16"
}
],
"name": "removeStake",
"outputs": [],
"stateMutability": "payable",
"type": "function"
}
]
]
75 changes: 39 additions & 36 deletions runtime/src/precompiles/solidity/staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,43 @@ pragma solidity ^0.8.0;
address constant ISTAKING_ADDRESS = 0x0000000000000000000000000000000000000801;

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

/**
* @dev Removes a subtensor stake `amount` from the specified `hotkey`.
*
* This function allows external accounts and contracts to unstake TAO from the subtensor pallet,
* which effectively calls `remove_stake` on the subtensor pallet with specified hotkey as a parameter
* and coldkey being the hashed address mapping of H160 sender address to Substrate ss58 address as
* implemented in Frontier HashedAddressMapping:
* https://github.com/polkadot-evm/frontier/blob/2e219e17a526125da003e64ef22ec037917083fa/frame/evm/src/lib.rs#L739
*
* @param hotkey The hotkey public key (32 bytes).
* @param amount The amount to unstake in rao.
*
* Requirements:
* - `hotkey` must be a valid hotkey registered on the network, ensuring that the stake is
* correctly attributed.
* - The existing stake amount must be not lower than specified amount
*/
function removeStake(bytes32 hotkey, uint256 amount) external;
}
/**
* @dev Removes a subtensor stake `amount` from the specified `hotkey`.
*
* This function allows external accounts and contracts to unstake TAO from the subtensor pallet,
* which effectively calls `remove_stake` on the subtensor pallet with specified hotkey as a parameter
* and coldkey being the hashed address mapping of H160 sender address to Substrate ss58 address as
* implemented in Frontier HashedAddressMapping:
* https://github.com/polkadot-evm/frontier/blob/2e219e17a526125da003e64ef22ec037917083fa/frame/evm/src/lib.rs#L739
*
* @param hotkey The hotkey public key (32 bytes).
* @param amount The amount to unstake in rao.
* @param netuid The subnet to stake to (uint16). Currently a noop, functionality will be enabled with RAO.
*
* Requirements:
* - `hotkey` must be a valid hotkey registered on the network, ensuring that the stake is
* correctly attributed.
* - The existing stake amount must be not lower than specified amount
*/
function removeStake(bytes32 hotkey, uint256 amount, uint16 netuid) external;
}
4 changes: 2 additions & 2 deletions runtime/src/precompiles/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ impl StakingPrecompile {
.map_or_else(vec::Vec::new, |slice| slice.to_vec()); // Avoiding borrowing conflicts

match method_id {
id if id == get_method_id("addStake(bytes32)") => {
id if id == get_method_id("addStake(bytes32,uint16)") => {
Self::add_stake(handle, &method_input)
}
id if id == get_method_id("removeStake(bytes32,uint256)") => {
id if id == get_method_id("removeStake(bytes32,uint256,uint16)") => {
Self::remove_stake(handle, &method_input)
}
_ => Err(PrecompileFailure::Error {
Expand Down

0 comments on commit 514af7f

Please sign in to comment.