Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions evm-tests/src/contracts/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
35 changes: 35 additions & 0 deletions evm-tests/src/subtensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,4 +351,39 @@ export async function setMaxChildkeyTake(api: TypedApi<typeof devnet>, 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<typeof devnet>,
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<typeof devnet>,
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);
}
15 changes: 15 additions & 0 deletions evm-tests/test/staking.precompile.stake-get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())

})
})
13 changes: 13 additions & 0 deletions precompiles/src/solidity/stakingV2.abi
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getNominatorMinRequiredStake",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down
10 changes: 10 additions & 0 deletions precompiles/src/solidity/stakingV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
8 changes: 8 additions & 0 deletions precompiles/src/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,14 @@ where
Ok(stake.into())
}

#[precompile::public("getNominatorMinRequiredStake()")]
#[precompile::view]
fn get_nominator_min_required_stake(_handle: &mut impl PrecompileHandle) -> EvmResult<U256> {
let stake = pallet_subtensor::Pallet::<R>::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::<R>();
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading