Skip to content

[v10] SimSwap + Extrinsics Improvement#3091

Merged
basfroman merged 23 commits intoSDKv10from
feat/roman/fees-and-transactions-related-changes
Oct 9, 2025
Merged

[v10] SimSwap + Extrinsics Improvement#3091
basfroman merged 23 commits intoSDKv10from
feat/roman/fees-and-transactions-related-changes

Conversation

@basfroman
Copy link
Collaborator

Core Extrinsics Refactor & Fee Simulation Framework

Summary

This PR introduces a major improvement to the Subtensor extrinsics logic, focusing on fee simulation, parameter validation, and internal API consistency — without breaking any existing external interfaces or E2E tests.
The changes make the SDK more predictable, safer to use, and better aligned with on-chain metadata.


Changes include

  1. New class SimSwapResult:

    • Represents the result of a simulated swap operation (stake-related transactions).
    • Used for pre-computing fees and outcomes before actual on-chain execution.
  2. New subpackage bittensor.core.extrinsics.params:

    • Contains dataclasses and helpers for structured parameter extraction from extrinsics.
    • Simplifies interaction with chain calls and enforces consistent argument structures.
  3. New Subtensor methods:

    • subtensor.sim_swap: Simulates fees for any staking-related transaction.
    • subtensor.validate_extrinsic_params: Validates and filters extrinsic parameters against on-chain metadata.
    • subtensor.compose_call: Now uses built-in validation via validate_extrinsic_params before composing a GenericCall.
    • subtensor.get_extrinsic_fee: Returns the full fee breakdown for any extrinsic call.
  4. Updated Subtensor methods:

    • get_stake_add_fee: Updated parameter list. now uses sim_swap for fee computation.
    • get_stake_movement_fee: Updated parameter list. now uses sim_swap for fee computation.
    • get_unstake_fee: Updated parameter list. now uses sim_swap for fee computation.
    • get_transfer_fee: Now uses Subtensor.compose_call with integrated pre-validation.
  5. Standardized extrinsic argument order (wallet, netuid, coldkey_ss58, hotkey_ss58, ...). The following methods now follow a consistent signature pattern across Subtensor's extrinsic related methods:

    • move_stake
    • set_children
    • unstake_all

Additional improvements

  1. ExtrinsicResponse class:

    • Added new fields: transaction_tao_fee, transaction_alpha_fee.
    • Improved unlock_wallet handling logic for safer cleanup.
  2. Critically important function check_balance_amount:

    • Extended validation logic for pre-transfer balance checks.
  3. SubtensorApi class:

    • Updated to integrate the new parameter validation and fee simulation mechanisms.

Notes:

  • The new implementation prevents invalid extrinsic submissions by validating parameters against live chain metadata before dispatch.
  • No breaking changes were introduced — all existing E2E tests pass without modification (except for minor formatting and unused import removals).
  • Developers now gain a safer and more transparent workflow when building or simulating transactions, while maintaining full backward compatibility.

Benefits

  • Safer on-chain calls through strict metadata-based validation.
  • Unified and cleaner extrinsics API.
  • Easier debugging and better fee transparency.
  • No changes required for existing test suites or external SDK consumers.

More datafiles in MIGRATION file on this PR.

@basfroman basfroman requested a review from a team October 8, 2025 23:08
@basfroman basfroman self-assigned this Oct 8, 2025
@basfroman basfroman added the enhancement New feature or request label Oct 8, 2025
@basfroman basfroman mentioned this pull request Oct 8, 2025
@basfroman basfroman changed the title SimSwap + Extrinsics Improvement [v10] SimSwap + Extrinsics Improvement Oct 8, 2025
@basfroman basfroman merged commit d41db6a into SDKv10 Oct 9, 2025
351 checks passed
@basfroman basfroman deleted the feat/roman/fees-and-transactions-related-changes branch October 9, 2025 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants