Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions contract-tests/src/contracts/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,13 @@ export const IStakingV2ABI = [
"inputs": [
{
"internalType": "address",
"name": "source_address",
"name": "sourceAddress",
"type": "address"
},
{
"internalType": "bytes32",
"name": "destination_coldkey",
"type": "bytes32"
"internalType": "address",
"name": "destinationAddress",
"type": "address"
},
{
"internalType": "bytes32",
Expand All @@ -572,12 +572,12 @@ export const IStakingV2ABI = [
},
{
"internalType": "uint256",
"name": "origin_netuid",
"name": "originNetuid",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "destination_netuid",
"name": "destinationNetuid",
"type": "uint256"
},
{
Expand Down
6 changes: 3 additions & 3 deletions contract-tests/test/staking.precompile.approval.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe("Test approval in staking precompile", () => {
const contract = new ethers.Contract(ISTAKING_V2_ADDRESS, IStakingV2ABI, wallet2);
const tx = await contract.transferStakeFrom(
wallet1.address, // source
convertH160ToPublicKey(wallet2.address), // distination
wallet2.address, // destination
hotkey.publicKey,
stakeNetuid,
stakeNetuid,
Expand Down Expand Up @@ -134,7 +134,7 @@ describe("Test approval in staking precompile", () => {
// wallet2 transfer from wallet1
const tx = await contract.transferStakeFrom(
wallet1.address, // source
convertH160ToPublicKey(wallet2.address), // destination
wallet2.address, // destination
hotkey.publicKey,
stakeNetuid,
stakeNetuid,
Expand Down Expand Up @@ -162,7 +162,7 @@ describe("Test approval in staking precompile", () => {
const contract = new ethers.Contract(ISTAKING_V2_ADDRESS, IStakingV2ABI, wallet2);
const tx = await contract.transferStakeFrom(
wallet1.address, // source
convertH160ToPublicKey(wallet2.address), // distination
wallet2.address, // destination
hotkey.publicKey,
stakeNetuid,
stakeNetuid,
Expand Down
12 changes: 6 additions & 6 deletions precompiles/src/solidity/stakingV2.abi
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,13 @@
"inputs": [
{
"internalType": "address",
"name": "source_address",
"name": "sourceAddress",
"type": "address"
},
{
"internalType": "bytes32",
"name": "destination_coldkey",
"type": "bytes32"
"internalType": "address",
"name": "destinationAddress",
"type": "address"
},
{
"internalType": "bytes32",
Expand All @@ -512,12 +512,12 @@
},
{
"internalType": "uint256",
"name": "origin_netuid",
"name": "originNetuid",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "destination_netuid",
"name": "destinationNetuid",
"type": "uint256"
},
{
Expand Down
28 changes: 14 additions & 14 deletions precompiles/src/solidity/stakingV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -382,34 +382,34 @@ interface IStaking {
) external;

/**
* @dev Transfer a subtensor stake `amount` associated with the `source_address` to a different coldkey
* `destination_coldkey`. The `source_address` must have approved beforehand the transaction signer
* @dev Transfer a subtensor stake `amount` associated with the `sourceAddress` to a different
* destination address. The `sourceAddress` must have approved beforehand the transaction signer
* (spender) to spend at least the `amount` (allowance). The allowance towards that spender will be
* decreased by this amount.
*
* This function allows external accounts and contracts to transfer staked TAO to another coldkey,
* which effectively calls `transfer_stake` on the subtensor pallet with specified destination
* coldkey as a parameter being the hashed address mapping of H160 sender address to Substrate ss58
* address as implemented in Frontier HashedAddressMapping:
* This function allows external accounts and contracts to transfer staked TAO to another EVM
* address, which effectively calls `transfer_stake` on the subtensor pallet. Both the source and
* destination EVM addresses are converted to their Substrate ss58 representation using Frontier
* HashedAddressMapping:
* https://github.com/polkadot-evm/frontier/blob/2e219e17a526125da003e64ef22ec037917083fa/frame/evm/src/lib.rs#L739
*
* @param source_address The source address (20 bytes).
* @param destination_coldkey The destination coldkey public key (32 bytes).
* @param sourceAddress The source address (20 bytes).
* @param destinationAddress The destination EVM address (20 bytes).
* @param hotkey The hotkey public key (32 bytes).
* @param origin_netuid The subnet to move stake from (uint256).
* @param destination_netuid The subnet to move stake to (uint256).
* @param originNetuid The subnet to move stake from (uint256).
* @param destinationNetuid The subnet to move stake to (uint256).
* @param amount The amount to move in rao.
*
* Requirements:
* - `origin_hotkey` and `destination_hotkey` must be valid hotkeys registered on the network, ensuring
* that the stake is correctly attributed.
*/
function transferStakeFrom(
address source_address,
bytes32 destination_coldkey,
address sourceAddress,
address destinationAddress,
bytes32 hotkey,
uint256 origin_netuid,
uint256 destination_netuid,
uint256 originNetuid,
uint256 destinationNetuid,
uint256 amount
) external;
}
7 changes: 4 additions & 3 deletions precompiles/src/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,19 +634,20 @@ where
Ok(())
}

#[precompile::public("transferStakeFrom(address,bytes32,bytes32,uint256,uint256,uint256)")]
#[precompile::public("transferStakeFrom(address,address,bytes32,uint256,uint256,uint256)")]
fn transfer_stake_from(
handle: &mut impl PrecompileHandle,
source_address: Address,
destination_coldkey: H256,
destination_address: Address,
hotkey: H256,
origin_netuid: U256,
destination_netuid: U256,
amount_alpha: U256,
) -> EvmResult<()> {
let spender = handle.context().caller;
let source_address = source_address.0;
let destination_coldkey = R::AccountId::from(destination_coldkey.0);
let destination_coldkey =
<R as pallet_evm::Config>::AddressMapping::into_account_id(destination_address.0);
let hotkey = R::AccountId::from(hotkey.0);
let origin_netuid = try_u16_from_u256(origin_netuid)?;
let destination_netuid = try_u16_from_u256(destination_netuid)?;
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// `spec_version`, and `authoring_version` are the same between Wasm and native.
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 399,
spec_version: 400,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
Loading