Skip to content

Commit cd565b2

Browse files
committed
try_initialize_v3
1 parent a0830a7 commit cd565b2

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

pallets/subtensor/src/subnets/subnet.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::*;
22
use sp_core::Get;
33
use subtensor_runtime_common::{NetUid, TaoCurrency};
4+
use subtensor_swap_interface::SwapHandler;
45

56
impl<T: Config> Pallet<T> {
67
/// Fetches the total count of subnets.
@@ -101,23 +102,23 @@ impl<T: Config> Pallet<T> {
101102
/// Facilitates user registration of a new subnetwork.
102103
///
103104
/// ### Args
104-
/// * **`origin`** – `T::RuntimeOrigin` &nbsp;Must be **signed** by the coldkey.
105-
/// * **`hotkey`** – `&T::AccountId` &nbsp;First neuron of the new subnet.
106-
/// * **`mechid`** – `u16` &nbsp;Only the dynamic mechanism (`1`) is currently supported.
105+
/// * **`origin`** – `T::RuntimeOrigin` &nbsp;Must be **signed** by the coldkey.
106+
/// * **`hotkey`** – `&T::AccountId` &nbsp;First neuron of the new subnet.
107+
/// * **`mechid`** – `u16` &nbsp;Only the dynamic mechanism (`1`) is currently supported.
107108
/// * **`identity`** – `Option<SubnetIdentityOfV3>` &nbsp;Optional metadata for the subnet.
108109
///
109110
/// ### Events
110-
/// * `NetworkAdded(netuid, mechid)` – always.
111-
/// * `SubnetIdentitySet(netuid)` – when a custom identity is supplied.
111+
/// * `NetworkAdded(netuid, mechid)` – always.
112+
/// * `SubnetIdentitySet(netuid)` – when a custom identity is supplied.
112113
/// * `NetworkRemoved(netuid)` – when a subnet is pruned to make room.
113114
///
114115
/// ### Errors
115-
/// * `NonAssociatedColdKey` – `hotkey` already belongs to another coldkey.
116-
/// * `MechanismDoesNotExist` – unsupported `mechid`.
117-
/// * `NetworkTxRateLimitExceeded` – caller hit the register-network rate limit.
118-
/// * `SubnetLimitReached` – limit hit **and** no eligible subnet to prune.
119-
/// * `CannotAffordLockCost` – caller lacks the lock cost.
120-
/// * `BalanceWithdrawalError` – failed to lock balance.
116+
/// * `NonAssociatedColdKey` – `hotkey` already belongs to another coldkey.
117+
/// * `MechanismDoesNotExist` – unsupported `mechid`.
118+
/// * `NetworkTxRateLimitExceeded` – caller hit the register-network rate limit.
119+
/// * `SubnetLimitReached` – limit hit **and** no eligible subnet to prune.
120+
/// * `CannotAffordLockCost` – caller lacks the lock cost.
121+
/// * `BalanceWithdrawalError` – failed to lock balance.
121122
/// * `InvalidIdentity` – supplied `identity` failed validation.
122123
///
123124
pub fn do_register_network(
@@ -255,6 +256,8 @@ impl<T: Config> Pallet<T> {
255256
Self::deposit_event(Event::SubnetIdentitySet(netuid_to_register));
256257
}
257258

259+
T::SwapInterface::try_initialize_v3(netuid_to_register)?;
260+
258261
// --- 18. Emit the NetworkAdded event.
259262
log::info!("NetworkAdded( netuid:{netuid_to_register:?}, mechanism:{mechid:?} )");
260263
Self::deposit_event(Event::NetworkAdded(netuid_to_register, mechid));

pallets/swap-interface/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub trait SwapHandler<AccountId> {
3535
);
3636
fn is_user_liquidity_enabled(netuid: NetUid) -> bool;
3737
fn dissolve_all_liquidity_providers(netuid: NetUid) -> DispatchResult;
38+
fn try_initialize_v3(netuid: NetUid) -> DispatchResult;
3839
}
3940

4041
#[derive(Debug, PartialEq)]

pallets/swap/src/pallet/impls.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,9 @@ impl<T: Config> SwapHandler<T::AccountId> for Pallet<T> {
15751575
fn dissolve_all_liquidity_providers(netuid: NetUid) -> DispatchResult {
15761576
Self::do_dissolve_all_liquidity_providers(netuid)
15771577
}
1578+
fn try_initialize_v3(netuid: NetUid) -> DispatchResult {
1579+
Self::maybe_initialize_v3(netuid).map_err(|e| e.into())
1580+
}
15781581
}
15791582

15801583
#[derive(Debug, PartialEq)]

0 commit comments

Comments
 (0)