Skip to content

Feat/recycle burn chain exts#2560

Open
LandynDev wants to merge 3 commits intoopentensor:devnet-readyfrom
LandynDev:feat/recycle-burn-chain-exts
Open

Feat/recycle burn chain exts#2560
LandynDev wants to merge 3 commits intoopentensor:devnet-readyfrom
LandynDev:feat/recycle-burn-chain-exts

Conversation

@LandynDev
Copy link
Copy Markdown

@LandynDev LandynDev commented Apr 2, 2026

Description

Add 4 new chain extension functions (IDs 16-19) enabling WASM smart contracts to recycle and burn alpha stake.

  • RecycleAlphaV1 (16): Recycle alpha stake
  • BurnAlphaV1 (17): Burn alpha stake
  • AddStakeRecycleV1 (18): Atomically add TAO stake then recycle
  • AddStakeBurnV1 (19): Atomically add TAO stake then burn

All functions return the actual alpha amount via the output buffer.

Related Issue(s)

Closes #2564

Type of Change

  • New feature (non-breaking change which adds functionality)

Breaking Change

No breaking changes. Existing chain extension functions (IDs 0-15) are unaffected. New function IDs 16-19 are additive.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run ./scripts/fix_rust.sh to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Additional Notes

7 unit tests cover: success paths for all 4 functions, root subnet rejection, nonexistent subnet, and insufficient balance. E2E validated on localnet with an ink! contract calling add_stake_recycle via chain extension.

I also ran some local E2E testing with a local running subtensor chain (with the new extensions), deployed contract, etc.

Screenshot 1 shows:

  • Accumulated fees of 0.0034 TAO on the contract (to be recycled)
  • Total recycled fees of 0.0000 TAO on the contract
  • Contract Balance of 5.0000 TAO
image

Screenshot 2 shows:

  • Recycle of 0.0034 TAO succeeded (CLI -> Smart contract func -> New add stake + recycle chain ext)
  • Accumulated fees of 0.0000 TAO on the contract (it got recycled)
  • Total recycled fees of 0.0034 TAO on the contract
  • Contract Balance of 4.9966 TAO
image

Unit tests successfully passing:
image

Strip development log::info!/log::error! calls from dispatch entry
and AddStakeRecycleV1 handler. Normalize AddStakeRecycleV1 to use
the same concise ? pattern as all other handlers.
@open-junius
Copy link
Copy Markdown
Contributor

Thanks for the contribution. Can you add the ticket for the requirement? I am wondering the extension like AddStakeRecycleV1, who really want to do it. just confirm all is from the real requirements.

@LandynDev
Copy link
Copy Markdown
Author

Thanks for the contribution. Can you add the ticket for the requirement? I am wondering the extension like AddStakeRecycleV1, who really want to do it. just confirm all is from the real requirements.

Just got it ticketed up here - #2564

Particular snippet from the issue to elaborate on the AddStakeBurn + AddStakeRecycle funcs and why those 2 are included:

The current AddStakeV1 chain extension only returns a success/error code, not the resulting alpha amount. While a contract could work around this by calling AddStakeV1 followed by RecycleAlphaV1(MAX), this recycles all alpha the contract holds on that subnet — not just the alpha from that specific stake. This is fine for simple contracts, but may break down for contracts that hold alpha for multiple purposes on the same subnet.

The AddStakeRecycleV1 and AddStakeBurnV1 functions handle this atomically in a single call, recycling/burning only the alpha produced by that specific stake. This provides the robustness needed for a general-purpose chain extension interface.

@LandynDev LandynDev marked this pull request as ready for review April 3, 2026 16:11
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.

2 participants