From caf693dfa281b4ccf4924af67034dd6527c05326 Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 11 Jul 2025 11:42:10 +0800 Subject: [PATCH 1/2] add getNominatorMinRequiredStake in precompile --- evm-tests/src/contracts/staking.ts | 13 +++++++ evm-tests/src/subtensor.ts | 35 +++++++++++++++++++ .../test/staking.precompile.stake-get.test.ts | 15 ++++++++ precompiles/src/solidity/stakingV2.abi | 13 +++++++ precompiles/src/solidity/stakingV2.sol | 10 ++++++ precompiles/src/staking.rs | 8 +++++ 6 files changed, 94 insertions(+) diff --git a/evm-tests/src/contracts/staking.ts b/evm-tests/src/contracts/staking.ts index 55c3ed33e6..7b9e671c23 100644 --- a/evm-tests/src/contracts/staking.ts +++ b/evm-tests/src/contracts/staking.ts @@ -252,6 +252,19 @@ export const IStakingV2ABI = [ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "getNominatorMinRequiredStake", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { diff --git a/evm-tests/src/subtensor.ts b/evm-tests/src/subtensor.ts index e3d5526268..5c886514ae 100644 --- a/evm-tests/src/subtensor.ts +++ b/evm-tests/src/subtensor.ts @@ -351,4 +351,39 @@ export async function setMaxChildkeyTake(api: TypedApi, take: num const tx = api.tx.Sudo.sudo({ call: internalCall.decodedCall }) await waitForTransactionWithRetry(api, tx, alice) +} + +// Swap coldkey to contract address +export async function swapColdkey( + api: TypedApi, + coldkey: KeyPair, + contractAddress: string, +) { + const alice = getAliceSigner(); + const internal_tx = api.tx.SubtensorModule.swap_coldkey({ + old_coldkey: convertPublicKeyToSs58(coldkey.publicKey), + new_coldkey: convertH160ToSS58(contractAddress), + swap_cost: tao(10), + }); + const tx = api.tx.Sudo.sudo({ + call: internal_tx.decodedCall, + }); + await waitForTransactionWithRetry(api, tx, alice); +} + +// Set target registrations per interval to 1000 +export async function setTargetRegistrationsPerInterval( + api: TypedApi, + netuid: number, +) { + const alice = getAliceSigner(); + const internal_tx = api.tx.AdminUtils + .sudo_set_target_registrations_per_interval({ + netuid, + target_registrations_per_interval: 1000, + }); + const tx = api.tx.Sudo.sudo({ + call: internal_tx.decodedCall, + }); + await waitForTransactionWithRetry(api, tx, alice); } \ No newline at end of file diff --git a/evm-tests/test/staking.precompile.stake-get.test.ts b/evm-tests/test/staking.precompile.stake-get.test.ts index 460aeabf32..d9cc79aeab 100644 --- a/evm-tests/test/staking.precompile.stake-get.test.ts +++ b/evm-tests/test/staking.precompile.stake-get.test.ts @@ -57,4 +57,19 @@ describe("Test staking precompile get methods", () => { assert.ok(alpha > 0) }) + + it("Get nominator min required stake", async () => { + const contract = new ethers.Contract( + ISTAKING_V2_ADDRESS, + IStakingV2ABI, + wallet1 + ); + + const stake = await contract.getNominatorMinRequiredStake() + const stakeOnChain = await api.query.SubtensorModule.NominatorMinRequiredStake.getValue() + + assert.ok(stake !== undefined) + assert.equal(stake.toString(), stakeOnChain.toString()) + + }) }) diff --git a/precompiles/src/solidity/stakingV2.abi b/precompiles/src/solidity/stakingV2.abi index 6772a15905..2c936898ab 100644 --- a/precompiles/src/solidity/stakingV2.abi +++ b/precompiles/src/solidity/stakingV2.abi @@ -183,6 +183,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "getNominatorMinRequiredStake", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { diff --git a/precompiles/src/solidity/stakingV2.sol b/precompiles/src/solidity/stakingV2.sol index f9feafd07b..c8c39761ad 100644 --- a/precompiles/src/solidity/stakingV2.sol +++ b/precompiles/src/solidity/stakingV2.sol @@ -195,6 +195,16 @@ interface IStaking { uint256 netuid ) external view returns (uint256); + /** + * @dev Returns the minimum required stake for a nominator. + * + * This function retrieves the minimum required stake for a nominator. + * It is a view function, meaning it does not modify the state of the contract and is free to call. + * + * @return The minimum required stake for a nominator. + */ + function getNominatorMinRequiredStake() external view returns (uint256); + /** * @dev Adds a subtensor stake `amount` associated with the `hotkey` within a price limit. * diff --git a/precompiles/src/staking.rs b/precompiles/src/staking.rs index 1acee0514e..b07d32ec2b 100644 --- a/precompiles/src/staking.rs +++ b/precompiles/src/staking.rs @@ -291,6 +291,14 @@ where Ok(stake.into()) } + #[precompile::public("getNominatorMinRequiredStake()")] + #[precompile::view] + fn get_nominator_min_required_stake(_handle: &mut impl PrecompileHandle) -> EvmResult { + let stake = pallet_subtensor::Pallet::::get_nominator_min_required_stake(); + + Ok(stake.into()) + } + #[precompile::public("addProxy(bytes32)")] fn add_proxy(handle: &mut impl PrecompileHandle, delegate: H256) -> EvmResult<()> { let account_id = handle.caller_account_id::(); From beda29a3b2815ff8b15cba1007ada11933c93703 Mon Sep 17 00:00:00 2001 From: open-junius Date: Fri, 11 Jul 2025 11:53:56 +0800 Subject: [PATCH 2/2] bump version --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 384e841072..19b44a6e0b 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -218,7 +218,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 292, + spec_version: 293, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1,