BasketSwapped

Event v464 → current #151

Emitted when swap_basket, or one leg of swap_basket_many (v470), rebalances a validator beta basket.

View events on chain
Useful for: validatorsstakersanalyticsdevelopers

The Big Picture

From v464 this is the only event behind a change in what a basket holds. tao_mid is the TAO through the middle of the swap, the quantity the turnover bucket meters. When origin_netuid is root, alpha_sold is TAO at 1:1; when destination_netuid is root, alpha_bought is TAO. From v470 one extrinsic can emit several, one per swap_basket_many leg. Source: pallets/subtensor/src/staking/basket_trade.rs do_swap_basket at v467 and do_swap_basket_many_tracked at 923fd1fa7 (v470).

Why This Matters

If you hold shares of a validator fund, this is how you learn the fund changed what it is backed by. Nothing about your shares changed; the mix behind them did.

Example Scenario

BasketSwapped shows hotkey H sold 1,000 alpha of subnet 3 (alpha_sold), which fetched 40 TAO (tao_mid) and bought 950 alpha of subnet 7 (alpha_bought). Fund holders now carry subnet 7 exposure they did not have a block earlier.

Common Questions

Is tao_mid what the fund paid in fees?
No. It is the TAO that passed between the two legs. Fees are inside each leg like any AMM swap.

Use Cases

  • Maintain a per-fund composition ledger without re-reading every holding
  • Attribute a change in fund NAV to a trade rather than to price movement
  • Measure basket turnover against BasketDailyTurnoverCap

How to Use This Event

  • → Apply alpha_sold and alpha_bought to a per-(hotkey, netuid) holdings table
  • → Sum tao_mid per hotkey over 7200-block windows to see turnover use

From Chain Metadata

A validator rebalanced its beta basket: `alpha_sold` of `origin_netuid` was sold for `tao_mid` TAO, which bought `alpha_bought` of `destination_netuid`. Fund shares and staker entitlements are unaffected; only the fund's composition changed.

Triggers

Preconditions

  • The trade passed every gate and both AMM legs filled within bounds
  • For swap_basket_many, every leg in the call succeeded; the events are deposited in leg order after the last leg commits

Effects

Postconditions

  • The fund holds alpha_sold less on origin_netuid and alpha_bought more on destination_netuid
  • BasketTradeBucket for hotkey was debited by tao_mid

Side Effects

  • Fund shares and staker entitlements are unchanged; only the composition moved
  • Pool prices on both subnets moved by the two legs

Event Data

#NameTypeDescription
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_sold
AlphaBalance alpha_sold: Alpha amount in alpha-RAO (÷10⁹ for alpha)
4
tao_mid
TaoBalance tao_mid: TAO amount in RAO (÷10⁹ for TAO)
5
alpha_bought
AlphaBalance alpha_bought: Alpha amount in alpha-RAO (÷10⁹ for alpha)

Code Examples

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);

// Subscribe to BasketSwapped events
client.finalizedBlock$.subscribe(async (block) => {
  const events = await api.event.SubtensorModule.BasketSwapped.get(block.hash);
  for (const evt of events) {
    console.log("BasketSwapped:", evt.payload);
  }
});

Runtime Info

View Source
Pallet Index
7
Event Index
151
First Version
v464
Current Version
v472