swap_stake_limit
Call v233 → v277, v290 → v292, v297 → v298, v301 → v385, v391 → v424, v432 → current #90Swaps stake between subnets with price limit protection.
View calls on chainCall Workflow
Click items to navigate. Pan and zoom to explore.
The Big Picture
Swapping between subnets exchanges Alpha tokens at market rates. For large swaps, this conversion can move against you. swap_stake_limit adds price protection - your swap only executes if you get an acceptable exchange rate. Essential for large stakeholders who can't afford to swap at bad rates during volatile periods.
Why This Matters
A 10,000 TAO swap between subnets with 2% slippage costs 200 TAO. The limit protects you - if the Alpha exchange rate moves too far, your transaction fails. You keep your position and can retry when conditions improve.
Example Scenario
You have 1000 Alpha on subnet 1 and want to move to subnet 3. Current rate is 1.0. You'll accept 0.98 (2% slippage) but not worse. Call swap_stake_limit(origin_netuid=1, dest_netuid=3, amount=1000, limit_price=0.98, allow_partial=false). If rate is 0.99, you get 990 Alpha on subnet 3. If rate is 0.95, transaction fails - your subnet 1 Alpha stays put.
Common Questions
- How do I determine the right limit price?
- Check current Alpha prices for both subnets. The effective rate is origin/destination. Add a buffer for acceptable slippage (1-3% typical). Set limit at your floor.
- When should I use allow_partial?
- If you need to move some stake even at worse rates, use allow_partial=true. For all-or-nothing moves (better for large rebalances), use false.
- Is this more expensive than regular swap_stake?
- Slightly higher gas for the limit check logic, but negligible. The protection is worth far more than the extra fee.
Use Cases
- Rebalance between subnets with slippage protection
- Large subnet position moves without excessive price impact
- Algorithmic rebalancing with guaranteed price floors
- Protect against unfavorable Alpha exchange rates during subnet swaps
From Chain Metadata
Swaps a specified amount of stake from one subnet to another, while keeping the same coldkey and hotkey.
Migration Notes
origin_netuid changed from u16 to NetUid; destination_netuid changed from u16 to NetUid; alpha_amount changed from u64 to AlphaBalance; limit_price changed from u64 to TaoBalance
Update decoders: SCALE encoding is positional, so any signature change (added, removed, or type-changed fields, or storage shape changes) shifts byte offsets and existing decoders will misparse this item. Re-derive types from the new metadata.
Input Parameters
| # | Name | Type | Description |
|---|---|---|---|
| 0 | hotkey | AccountId | hotkey: Account address (32 bytes, SS58-encoded) (hex -> SS58) |
| 1 | origin_netuid | NetUid | origin_netuid: Subnet ID (u16, 0-65535) |
| 2 | destination_netuid | NetUid | destination_netuid: Subnet ID (u16, 0-65535) |
| 3 | alpha_amount | AlphaBalance | alpha_amount: Alpha amount in alpha-RAO (÷10⁹ for alpha) |
| 4 | limit_price | TaoBalance | limit_price: TAO amount in RAO (÷10⁹ for TAO) |
| 5 | allow_partial | bool | allow_partial (bool) |
Permissions
Permission data inferred from metadata. May be incomplete.
Requirements
- Has stake on origin subnet
- Price meets limit requirement
- Destination subnet exists and hotkey is registered
- From v488, when the origin or the destination is netuid 0: the queued basket dividend credits of the validator settle, or are snapshotted to its current root stakers, before the stake changes; it fails with BasketDepositPending when neither completes in this call (pallets/subtensor/src/staking/stake_utils.rs L1227-L1234 and L1334-L1337 and staking/basket_flush.rs L204-L225 at d967d1358, runtime v490)
Effects
Events Emitted
Storage Modified
Postconditions
- Stake swapped at acceptable price
- Alpha exchanged between subnet pools
Side Effects
- Partial fill possible if allow_partial is true
- Fill-or-kill if allow_partial is false
Possible Errors
Code Examples
// ----------------------------------------------------------------------
// HEADS UP: 1 arg below has a complex type with no usable default.
// Look for `undefined as any` and replace it with real value
// before running — the snippet compiles, but will fail at runtime as-is.
// ----------------------------------------------------------------------
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Build swap_stake_limit call (typed, named args)
const hotkey = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY";
const origin_netuid = 1;
const destination_netuid = 1;
const alpha_amount = 1_000_000_000n;
const limit_price = undefined as any /* TaoBalance — replace with real value */;
const allow_partial = true;
const tx = api.tx.SubtensorModule.swap_stake_limit({
hotkey,
origin_netuid,
destination_netuid,
alpha_amount,
limit_price,
allow_partial,
});On-Chain Activity
Primary protocol calls
#25 most used call
50–80% of submissions succeed
As of block 9,385,000
Version History
Runtime Info
View Source- Pallet Index
- 7
- Call Index
- 90
- First Version
- v233
- Current Version
- v490