-
Notifications
You must be signed in to change notification settings - Fork 244
Add pallet-contracts integration with Subtensor chain extension #2059
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
base: devnet-ready
Are you sure you want to change the base?
Add pallet-contracts integration with Subtensor chain extension #2059
Conversation
This proposal is groundbreaking, it open lot of native doors integration. |
Implement custom deposit calculation for contract storage with 15% of existential deposit per key and 6% per byte
I saw something in the docs saying the APIs for the extrinsics we allow has to remain stable. We solve this in the frontier (EVM) pallet by using precompiles with stable APIs but the underlying extrinsics can change. Possibly we should do the same because I'm not sure if we can guarantee the stability of any of the extrinsics at-present |
Also, @silva-fj let's actually remove the |
Yes that's correct, the whitelisted dispatchables should remain stable. This is not exactly as critical as on EVM contracts because ink contracts can be upgradable (just like the runtime). But ideally a stable API should be provided. This can be accomplished with chain extensions, by exposing an API that remains stable while the underlying dispatchables could be changed |
EVM contracts use an upgradeable pattern as well.
Possibly we can also just agree that the API is not stable and any contracts implementing the calls can check the runtime version to see if it has changed/if their current contract version (self-imposed) supports it. i.e. like a guard clause |
are you satisfied with this as is @camfairchild ? |
just a few tiny merge conflicts |
Define chain extension function IDs for staking operations and outcome codes for error handling
Expose 12 subtensor pallet functions to smart contracts: - GetStakeInfoForHotkeyColdkeyNetuidV1 (query) - AddStakeV1, RemoveStakeV1 - UnstakeAllV1, UnstakeAllAlphaV1 - MoveStakeV1, TransferStakeV1, SwapStakeV1 - AddStakeLimitV1, RemoveStakeLimitV1, SwapStakeLimitV1 - RemoveStakeFullLimitV1, SetColdkeyAutoStakeHotkeyV1
Resolved conflicts and updated chain-extensions to align with upstream removal of governance pallets.
Add FunctionId::AddProxyV1 (ID 13) for proxy management and three new error codes for proxy-specific failures: ProxyTooMany, ProxyDuplicate, and ProxyNoSelfProxy.
Add pallet-subtensor-proxy to dependencies for proxy chain extension support.
Add AddProxyV1 chain extension handler that calls pallet_proxy::add_proxy with ProxyType::Staking and zero delay, matching precompile behavior.
Configure pallet_proxy in mock runtime with ProxyType InstanceFilter implementation for chain extension tests.
Add test verifying AddProxyV1 creates proxy relationship with correct delegate, proxy type (Staking), and delay (0).
Document AddProxyV1 function (ID 13) and associated error codes in contracts documentation.
Remove add_proxy from whitelisted contract calls as it should be called via chain extension instead of direct runtime call.
Add FunctionId::RemoveProxyV1 (ID 14) and ProxyNotFound error code for proxy removal failures.
Add RemoveProxyV1 handler that calls pallet_proxy::remove_proxy with ProxyType::Staking and zero delay, matching add_proxy behavior.
Add test verifying RemoveProxyV1 successfully removes proxy relationship after it was created with AddProxyV1.
Document RemoveProxyV1 function (ID 14) and ProxyNotFound error code.
Summary
This PR integrates the
pallet-contracts
module into the Subtensor runtime, enabling wasm smart contract functionality with a custom chain extension for accessing Subtensor-specific features.Key Features
Custom Chain Extension: The following calls are exposed
- SubtensorModule::add_stake
- SubtensorModule::remove_stake
- SubtensorModule::unstake_all
- SubtensorModule::unstake_all_alpha
- SubtensorModule::move_stake
- SubtensorModule::transfer_stake
- SubtensorModule::swap_stake
- SubtensorModule::add_stake_limit
- SubtensorModule::remove_stake_limit
- SubtensorModule::swap_stake_limit
- SubtensorModule::remove_stake_full_limit
- SubtensorModule::set_coldkey_auto_stake_hotkey
- Proxy::add_proxy (Staking)
- Proxy::remove_proxy (Staking)
Restricted Call Filter: Whitelisted operations
Proxy::proxy
Conservative Configuration
Breaking Changes
None - This is an additive change that doesn't affect existing functionality.