Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transfer stake (untested) #1170

Open
wants to merge 6 commits into
base: devnet-ready
Choose a base branch
from

Conversation

bdmason
Copy link

@bdmason bdmason commented Jan 18, 2025

Transfer stake

Adds a new transfer_stake extrinsic. Needs testing.

@bdmason bdmason requested a review from unconst as a code owner January 18, 2025 17:57
pallets/subtensor/src/staking/transfer_stake.rs Outdated Show resolved Hide resolved
pallets/subtensor/src/staking/transfer_stake.rs Outdated Show resolved Hide resolved
Comment on lines 50 to 51

let origin_tao: u64 = Self::swap_alpha_for_tao(netuid, alpha_amount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let origin_tao: u64 = Self::swap_alpha_for_tao(netuid, alpha_amount);

If we swap here, we also have to swap back, otherwise we mess up the accounting.

Also might be fine to not swap at all.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer this, think I was just copying another event's arguments

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the swap entirely

pallets/subtensor/src/staking/transfer_stake.rs Outdated Show resolved Hide resolved
pallets/subtensor/src/staking/transfer_stake.rs Outdated Show resolved Hide resolved
@axionyu
Copy link

axionyu commented Jan 20, 2025

I have a suggestion here. I think the function can modified to be something like this for more flexibility when transferring stake.

pub fn do_transfer_stake(
    origin: T::RuntimeOrigin,
    source_hotkey: T::AccountId,
    dest_hotkey: T::AccountId
    destination_coldkey: T::AccountId,
    netuid: u16,
    alpha_amount: u64,
) 

The decrease_stake_for_hotkey_and_coldkey_on_subnet and increase_stake_for_hotkey_and_coldkey_on_subnet call can be modified to look something like this.

        // --- 5. Unstake the amount of alpha from the origin coldkey
        Self::decrease_stake_for_hotkey_and_coldkey_on_subnet(
            &source_hotkey.clone(),
            &coldkey.clone(),
            netuid,
            alpha_amount,
        );

        // --- 6. Stake the amount of alpha for the destination coldkey
        Self::increase_stake_for_hotkey_and_coldkey_on_subnet(
            &dest_hotkey.clone(),
            &destination_coldkey.clone(),
            netuid,
            alpha_amount,
        );

So this would support the following use cases:

  1. User can transfer the alpha stake from their current coldkey to another coldkey for a given hotkey on a subnet (current use case)
  2. User can transfer the alpha stake from a source hotkey to a destination hotkey. The stake will still be on the current coldkey (new use case) - For example, I want to transfer the stake from one validator to another validator in a single transaction.
  3. User can transfer the alpha stake from a source hotkey from the current coldkey to a destination hotkey on another coldkey. (new use case) - For example, I want to transfer the stake to a validator from my current wallet to another validator in a new wallet.

@camfairchild
Copy link
Contributor

camfairchild commented Jan 20, 2025

I have a suggestion here. I think the function can modified to be something like this for more flexibility when transferring stake.

So this would support the following use cases:

  1. User can transfer the alpha stake from a source hotkey to a destination hotkey. The stake will still be on the current coldkey (new use case) - For example, I want to transfer the stake from one validator to another validator in a single transaction.

We already have a function for this move_stake.

  1. User can transfer the alpha stake from a source hotkey from the current coldkey to a destination hotkey on another coldkey. (new use case) - For example, I want to transfer the stake to a validator from my current wallet to another validator in a new wallet.

I think we want to avoid this because we want to be able to enforce rate limits, etc.

It's possible that we replace move_stake with this function, as you're suggesting, but, as with 3., we have to be careful of how we handle the staking rate limits. And we have to charge the tx fee potentially differently, otherwise people will be paying for move_stake when they currently do not.

It's not a bad idea though as it makes things simpler from a user-perspective.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants