From d537112a07f54caa599b46d6991d6dcb8e6286a8 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 20 May 2025 14:57:25 +0200 Subject: [PATCH 1/7] Rename LiquidityDataProvider to SubnetInfo --- pallets/admin-utils/src/tests/mock.rs | 2 +- pallets/subtensor/src/lib.rs | 6 +++--- pallets/subtensor/src/tests/mock.rs | 2 +- pallets/subtensor/src/tests/swap_coldkey.rs | 2 +- pallets/swap-interface/src/lib.rs | 6 +++--- pallets/swap/src/mock.rs | 12 ++++++------ pallets/swap/src/pallet/impls.rs | 21 ++++++++++----------- pallets/swap/src/pallet/mod.rs | 14 +++++++------- runtime/src/lib.rs | 2 +- 9 files changed, 33 insertions(+), 34 deletions(-) diff --git a/pallets/admin-utils/src/tests/mock.rs b/pallets/admin-utils/src/tests/mock.rs index ff7ef14e7a..57d086b538 100644 --- a/pallets/admin-utils/src/tests/mock.rs +++ b/pallets/admin-utils/src/tests/mock.rs @@ -275,7 +275,7 @@ parameter_types! { impl pallet_subtensor_swap::Config for Test { type RuntimeEvent = RuntimeEvent; type AdminOrigin = EnsureRoot; - type LiquidityDataProvider = SubtensorModule; + type SubnetInfo = SubtensorModule; type BalanceOps = SubtensorModule; type ProtocolId = SwapProtocolId; type MaxFeeRate = SwapMaxFeeRate; diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 3371b7f804..6fef4dc6ee 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -2422,7 +2422,7 @@ impl CollectiveInterface for () { } impl> - subtensor_swap_interface::LiquidityDataProvider for Pallet + subtensor_swap_interface::SubnetInfo for Pallet { fn tao_reserve(netuid: u16) -> u64 { SubnetTAO::::get(netuid) @@ -2432,11 +2432,11 @@ impl> SubnetAlphaIn::::get(netuid) } - fn subnet_exist(netuid: u16) -> bool { + fn exists(netuid: u16) -> bool { Self::if_subnet_exist(netuid) } - fn subnet_mechanism(netuid: u16) -> u16 { + fn mechanism(netuid: u16) -> u16 { SubnetMechanism::::get(netuid) } } diff --git a/pallets/subtensor/src/tests/mock.rs b/pallets/subtensor/src/tests/mock.rs index e61ae02720..1f30b115ef 100644 --- a/pallets/subtensor/src/tests/mock.rs +++ b/pallets/subtensor/src/tests/mock.rs @@ -431,7 +431,7 @@ parameter_types! { impl pallet_subtensor_swap::Config for Test { type RuntimeEvent = RuntimeEvent; type AdminOrigin = EnsureRoot; - type LiquidityDataProvider = SubtensorModule; + type SubnetInfo = SubtensorModule; type BalanceOps = SubtensorModule; type ProtocolId = SwapProtocolId; type MaxFeeRate = SwapMaxFeeRate; diff --git a/pallets/subtensor/src/tests/swap_coldkey.rs b/pallets/subtensor/src/tests/swap_coldkey.rs index 74bc0a45c5..f796b9d88a 100644 --- a/pallets/subtensor/src/tests/swap_coldkey.rs +++ b/pallets/subtensor/src/tests/swap_coldkey.rs @@ -12,7 +12,7 @@ use frame_system::{Config, RawOrigin}; use sp_core::{Get, H256, U256}; use sp_runtime::DispatchError; use substrate_fixed::types::U96F32; -use subtensor_swap_interface::{LiquidityDataProvider, OrderType, SwapHandler}; +use subtensor_swap_interface::{OrderType, SubnetInfo, SwapHandler}; use super::mock; use super::mock::*; diff --git a/pallets/swap-interface/src/lib.rs b/pallets/swap-interface/src/lib.rs index e937883285..8ab9c5d1cc 100644 --- a/pallets/swap-interface/src/lib.rs +++ b/pallets/swap-interface/src/lib.rs @@ -41,11 +41,11 @@ pub struct UpdateLiquidityResult { pub fee_alpha: u64, } -pub trait LiquidityDataProvider { +pub trait SubnetInfo { fn tao_reserve(netuid: u16) -> u64; fn alpha_reserve(netuid: u16) -> u64; - fn subnet_exist(netuid: u16) -> bool; - fn subnet_mechanism(netuid: u16) -> u16; + fn exists(netuid: u16) -> bool; + fn mechanism(netuid: u16) -> u16; } pub trait BalanceOps { diff --git a/pallets/swap/src/mock.rs b/pallets/swap/src/mock.rs index 52c9e1c77a..e30c1978cc 100644 --- a/pallets/swap/src/mock.rs +++ b/pallets/swap/src/mock.rs @@ -12,7 +12,7 @@ use sp_runtime::{ BuildStorage, traits::{BlakeTwo256, IdentityLookup}, }; -use subtensor_swap_interface::{BalanceOps, LiquidityDataProvider}; +use subtensor_swap_interface::{BalanceOps, SubnetInfo}; construct_runtime!( pub enum Test { @@ -71,10 +71,10 @@ parameter_types! { pub const MinimumReserves: NonZeroU64 = NonZeroU64::new(1).unwrap(); } -// Mock implementor of LiquidityDataProvider trait +// Mock implementor of SubnetInfo trait pub struct MockLiquidityProvider; -impl LiquidityDataProvider for MockLiquidityProvider { +impl SubnetInfo for MockLiquidityProvider { fn tao_reserve(netuid: u16) -> u64 { match netuid { 123 => 10_000, @@ -89,11 +89,11 @@ impl LiquidityDataProvider for MockLiquidityProvider { } } - fn subnet_exist(_netuid: u16) -> bool { + fn exists(_netuid: u16) -> bool { true } - fn subnet_mechanism(netuid: u16) -> u16 { + fn mechanism(netuid: u16) -> u16 { if netuid == 0 { 0 } else { 1 } } } @@ -147,7 +147,7 @@ impl BalanceOps for MockBalanceOps { impl crate::pallet::Config for Test { type RuntimeEvent = RuntimeEvent; type AdminOrigin = EnsureRoot; - type LiquidityDataProvider = MockLiquidityProvider; + type SubnetInfo = MockLiquidityProvider; type BalanceOps = MockBalanceOps; type ProtocolId = SwapProtocolId; type MaxFeeRate = MaxFeeRate; diff --git a/pallets/swap/src/pallet/impls.rs b/pallets/swap/src/pallet/impls.rs index d9ee8a5d8f..1732fa2950 100644 --- a/pallets/swap/src/pallet/impls.rs +++ b/pallets/swap/src/pallet/impls.rs @@ -8,7 +8,7 @@ use sp_arithmetic::helpers_128bit; use sp_runtime::traits::AccountIdConversion; use substrate_fixed::types::{U64F64, U96F32}; use subtensor_swap_interface::{ - BalanceOps, LiquidityDataProvider, SwapHandler, SwapResult, UpdateLiquidityResult, + BalanceOps, SubnetInfo, SwapHandler, SwapResult, UpdateLiquidityResult, }; use super::pallet::*; @@ -249,8 +249,8 @@ impl Pallet { // Initialize the v3: // Reserves are re-purposed, nothing to set, just query values for liquidity and price calculation - let tao_reserve = ::LiquidityDataProvider::tao_reserve(netuid.into()); - let alpha_reserve = ::LiquidityDataProvider::alpha_reserve(netuid.into()); + let tao_reserve = ::SubnetInfo::tao_reserve(netuid.into()); + let alpha_reserve = ::SubnetInfo::alpha_reserve(netuid.into()); // Set price let price = U64F64::saturating_from_num(tao_reserve) @@ -319,9 +319,8 @@ impl Pallet { sqrt_price_limit: SqrtPrice, ) -> Result> { ensure!( - T::LiquidityDataProvider::tao_reserve(netuid.into()) >= T::MinimumReserve::get().get() - && T::LiquidityDataProvider::alpha_reserve(netuid.into()) - >= T::MinimumReserve::get().get(), + T::SubnetInfo::tao_reserve(netuid.into()) >= T::MinimumReserve::get().get() + && T::SubnetInfo::alpha_reserve(netuid.into()) >= T::MinimumReserve::get().get(), Error::::ReservesTooLow ); @@ -363,8 +362,8 @@ impl Pallet { ); } - let tao_reserve = T::LiquidityDataProvider::tao_reserve(netuid.into()); - let alpha_reserve = T::LiquidityDataProvider::alpha_reserve(netuid.into()); + let tao_reserve = T::SubnetInfo::tao_reserve(netuid.into()); + let alpha_reserve = T::SubnetInfo::alpha_reserve(netuid.into()); let checked_reserve = match order_type { OrderType::Buy => alpha_reserve, @@ -1061,11 +1060,11 @@ impl SwapHandler for Pallet { } fn current_alpha_price(netuid: u16) -> U96F32 { - match T::LiquidityDataProvider::subnet_mechanism(netuid) { + match T::SubnetInfo::mechanism(netuid) { 1 => { let sqrt_price = AlphaSqrtPrice::::get(NetUid::from(netuid)); - let tao_reserve = T::LiquidityDataProvider::tao_reserve(netuid); - let alpha_reserve = T::LiquidityDataProvider::alpha_reserve(netuid); + let tao_reserve = T::SubnetInfo::tao_reserve(netuid); + let alpha_reserve = T::SubnetInfo::alpha_reserve(netuid); if sqrt_price == 0 && tao_reserve > 0 && alpha_reserve > 0 { U96F32::saturating_from_num(tao_reserve) diff --git a/pallets/swap/src/pallet/mod.rs b/pallets/swap/src/pallet/mod.rs index ab35bd452b..082ce508fb 100644 --- a/pallets/swap/src/pallet/mod.rs +++ b/pallets/swap/src/pallet/mod.rs @@ -3,7 +3,7 @@ use core::num::NonZeroU64; use frame_support::{PalletId, pallet_prelude::*, traits::Get}; use frame_system::pallet_prelude::*; use substrate_fixed::types::U64F64; -use subtensor_swap_interface::{BalanceOps, LiquidityDataProvider}; +use subtensor_swap_interface::{BalanceOps, SubnetInfo}; use crate::{ NetUid, @@ -34,8 +34,8 @@ mod pallet { type AdminOrigin: EnsureOrigin; /// Implementor of - /// [`LiquidityDataProvider`](subtensor_swap_interface::LiquidityDataProvider). - type LiquidityDataProvider: LiquidityDataProvider; + /// [`SubnetInfo`](subtensor_swap_interface::SubnetInfo). + type SubnetInfo: SubnetInfo; /// Implementor of /// [`BalanceOps`](subtensor_swap_interface::BalanceOps). @@ -230,7 +230,7 @@ mod pallet { // Ensure that the subnet exists. ensure!( - T::LiquidityDataProvider::subnet_exist(netuid), + T::SubnetInfo::exists(netuid), Error::::SubNetworkDoesNotExist ); @@ -270,7 +270,7 @@ mod pallet { // Ensure that the subnet exists. ensure!( - T::LiquidityDataProvider::subnet_exist(netuid), + T::SubnetInfo::exists(netuid), Error::::SubNetworkDoesNotExist ); @@ -326,7 +326,7 @@ mod pallet { // Ensure that the subnet exists. ensure!( - T::LiquidityDataProvider::subnet_exist(netuid), + T::SubnetInfo::exists(netuid), Error::::SubNetworkDoesNotExist ); @@ -378,7 +378,7 @@ mod pallet { // Ensure that the subnet exists. ensure!( - T::LiquidityDataProvider::subnet_exist(netuid), + T::SubnetInfo::exists(netuid), Error::::SubNetworkDoesNotExist ); diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 78b32986c0..e037f31d76 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1131,7 +1131,7 @@ parameter_types! { impl pallet_subtensor_swap::Config for Runtime { type RuntimeEvent = RuntimeEvent; type AdminOrigin = EnsureRoot; - type LiquidityDataProvider = SubtensorModule; + type SubnetInfo = SubtensorModule; type BalanceOps = SubtensorModule; type ProtocolId = SwapProtocolId; type MaxFeeRate = SwapMaxFeeRate; From 11ee3defdfb25409f873170b6f8289732839f934 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 20 May 2025 15:48:38 +0200 Subject: [PATCH 2/7] Move sim_swap into swap pallet --- pallets/subtensor/src/lib.rs | 12 ++-- pallets/subtensor/src/staking/helpers.rs | 12 ++-- pallets/subtensor/src/staking/stake_utils.rs | 68 ++------------------ pallets/swap-interface/src/lib.rs | 5 ++ pallets/swap/src/pallet/impls.rs | 20 ++++++ 5 files changed, 41 insertions(+), 76 deletions(-) diff --git a/pallets/subtensor/src/lib.rs b/pallets/subtensor/src/lib.rs index 6fef4dc6ee..cb5c4bb0a8 100644 --- a/pallets/subtensor/src/lib.rs +++ b/pallets/subtensor/src/lib.rs @@ -2453,11 +2453,11 @@ impl> } fn increase_balance(coldkey: &T::AccountId, tao: u64) { - Self::add_balance_to_coldkey_account(&coldkey, tao) + Self::add_balance_to_coldkey_account(coldkey, tao) } fn decrease_balance(coldkey: &T::AccountId, tao: u64) -> Result { - Self::remove_balance_from_coldkey_account(&coldkey, tao) + Self::remove_balance_from_coldkey_account(coldkey, tao) } fn increase_stake( @@ -2467,11 +2467,11 @@ impl> alpha: u64, ) -> Result<(), DispatchError> { ensure!( - Self::hotkey_account_exists(&hotkey), + Self::hotkey_account_exists(hotkey), Error::::HotKeyAccountNotExists ); - Self::increase_stake_for_hotkey_and_coldkey_on_subnet(&hotkey, &coldkey, netuid, alpha); + Self::increase_stake_for_hotkey_and_coldkey_on_subnet(hotkey, coldkey, netuid, alpha); Ok(()) } @@ -2483,12 +2483,12 @@ impl> alpha: u64, ) -> Result { ensure!( - Self::hotkey_account_exists(&hotkey), + Self::hotkey_account_exists(hotkey), Error::::HotKeyAccountNotExists ); Ok(Self::decrease_stake_for_hotkey_and_coldkey_on_subnet( - &hotkey, &coldkey, netuid, alpha, + hotkey, coldkey, netuid, alpha, )) } } diff --git a/pallets/subtensor/src/staking/helpers.rs b/pallets/subtensor/src/staking/helpers.rs index 1e105e46b2..edabf4d64c 100644 --- a/pallets/subtensor/src/staking/helpers.rs +++ b/pallets/subtensor/src/staking/helpers.rs @@ -1,8 +1,3 @@ -use super::*; -use safe_math::*; -use substrate_fixed::types::U96F32; -use subtensor_swap_interface::SwapHandler; - use frame_support::traits::{ Imbalance, tokens::{ @@ -10,6 +5,11 @@ use frame_support::traits::{ fungible::{Balanced as _, Inspect as _}, }, }; +use safe_math::*; +use substrate_fixed::types::U96F32; +use subtensor_swap_interface::{OrderType, SwapHandler}; + +use super::*; impl Pallet { // Returns true if the passed hotkey allow delegative staking. @@ -70,7 +70,7 @@ impl Pallet { let alpha_stake = Self::get_stake_for_hotkey_and_coldkey_on_subnet( hotkey, coldkey, netuid, ); - Self::sim_swap_alpha_for_tao(netuid, alpha_stake) + T::SwapInterface::sim_swap(netuid, OrderType::Sell, alpha_stake) .map(|r| { let fee: u64 = U96F32::saturating_from_num(r.fee_paid) .saturating_mul(T::SwapInterface::current_alpha_price(netuid)) diff --git a/pallets/subtensor/src/staking/stake_utils.rs b/pallets/subtensor/src/staking/stake_utils.rs index 14bf659655..4495e521c8 100644 --- a/pallets/subtensor/src/staking/stake_utils.rs +++ b/pallets/subtensor/src/staking/stake_utils.rs @@ -596,66 +596,6 @@ impl Pallet { actual_alpha.neg().max(0).unsigned_abs() } - /// Calculates Some(Alpha) returned from pool by staking operation - /// if liquidity allows that. If not, returns None. - /// - /// If new alpha_reserve is about to drop below DefaultMinimumPoolLiquidity, - /// then don't do it. - /// - pub fn sim_swap_tao_for_alpha(netuid: u16, tao: u64) -> Result { - // Step 1: Get the mechanism type for the subnet (0 for Stable, 1 for Dynamic) - let mechanism_id: u16 = SubnetMechanism::::get(netuid); - // Step 2: Simulate swapping tao and attain alpha - if mechanism_id == 1 { - T::SwapInterface::swap( - netuid, - OrderType::Buy, - tao, - T::SwapInterface::max_price(), - true, - ) - } else { - // Step 3.b.1: Stable mechanism, just return the value 1:1 - Ok(SwapResult { - amount_paid_in: tao, - amount_paid_out: tao, - fee_paid: 0, - new_tao_reserve: 0, - new_alpha_reserve: 0, - }) - } - } - - /// Calculates Some(Tao) returned from pool by unstaking operation - /// if liquidity allows that. If not, returns None. - /// - /// If new tao_reserve is about to drop below DefaultMinimumPoolLiquidity, - /// then don't do it. - /// - pub fn sim_swap_alpha_for_tao(netuid: u16, alpha: u64) -> Result { - // Step 1: Get the mechanism type for the subnet (0 for Stable, 1 for Dynamic) - let mechanism_id: u16 = SubnetMechanism::::get(netuid); - // Step 2: Simulate swapping alpha and attain tao - if mechanism_id == 1 { - T::SwapInterface::swap( - netuid, - OrderType::Sell, - alpha, - T::SwapInterface::min_price(), - true, - ) - } else { - // Step 3.b.1: Stable mechanism, just return the value 1:1 - Ok(SwapResult { - amount_paid_in: alpha, - amount_paid_out: alpha, - fee_paid: 0, - new_tao_reserve: 0, - new_alpha_reserve: 0, - }) - } - } - /// Swaps TAO for the alpha token on the subnet. /// /// Updates TaoIn, AlphaIn, and AlphaOut @@ -900,7 +840,7 @@ impl Pallet { // Get the minimum balance (and amount) that satisfies the transaction let min_amount = { let min_stake = DefaultMinStake::::get(); - let fee = Self::sim_swap_tao_for_alpha(netuid, min_stake) + let fee = T::SwapInterface::sim_swap(netuid, OrderType::Buy, min_stake) .map(|res| res.fee_paid) .unwrap_or(T::SwapInterface::approx_fee_amount(netuid, min_stake)); min_stake.saturating_add(fee) @@ -927,7 +867,7 @@ impl Pallet { Error::::HotKeyAccountNotExists ); - let expected_alpha = Self::sim_swap_tao_for_alpha(netuid, stake_to_be_added) + let expected_alpha = T::SwapInterface::sim_swap(netuid, OrderType::Buy, stake_to_be_added) .map_err(|_| Error::::InsufficientLiquidity)?; ensure!( @@ -960,7 +900,7 @@ impl Pallet { ensure!(Self::if_subnet_exist(netuid), Error::::SubnetNotExists); // Ensure that the stake amount to be removed is above the minimum in tao equivalent. - match Self::sim_swap_alpha_for_tao(netuid, alpha_unstaked) { + match T::SwapInterface::sim_swap(netuid, OrderType::Sell, alpha_unstaked) { Ok(res) => ensure!( res.amount_paid_out > DefaultMinStake::::get(), Error::::AmountTooLow @@ -1040,7 +980,7 @@ impl Pallet { ); // Ensure that the stake amount to be removed is above the minimum in tao equivalent. - let tao_equivalent = Self::sim_swap_alpha_for_tao(origin_netuid, alpha_amount) + let tao_equivalent = T::SwapInterface::sim_swap(origin_netuid, OrderType::Sell, alpha_amount) .map(|res| res.amount_paid_out) .map_err(|_| Error::::InsufficientLiquidity)?; ensure!( diff --git a/pallets/swap-interface/src/lib.rs b/pallets/swap-interface/src/lib.rs index 8ab9c5d1cc..5f6213e534 100644 --- a/pallets/swap-interface/src/lib.rs +++ b/pallets/swap-interface/src/lib.rs @@ -17,6 +17,11 @@ pub trait SwapHandler { price_limit: u64, should_rollback: bool, ) -> Result; + fn sim_swap( + netuid: u16, + order_t: OrderType, + amount: u64, + ) -> Result; fn approx_fee_amount(netuid: u16, amount: u64) -> u64; fn current_alpha_price(netuid: u16) -> U96F32; fn max_price() -> u64; diff --git a/pallets/swap/src/pallet/impls.rs b/pallets/swap/src/pallet/impls.rs index 1732fa2950..a70c23f1c3 100644 --- a/pallets/swap/src/pallet/impls.rs +++ b/pallets/swap/src/pallet/impls.rs @@ -1055,6 +1055,26 @@ impl SwapHandler for Pallet { .map_err(Into::into) } + fn sim_swap(netuid: u16, order_t: OrderType, amount: u64) -> Result { + match T::SubnetInfo::mechanism(netuid) { + 1 => { + let price_limit = match order_t { + OrderType::Buy => Self::max_price(), + OrderType::Sell => Self::min_price(), + }; + + Self::swap(netuid, order_t, amount, price_limit, true) + } + _ => Ok(SwapResult { + amount_paid_in: amount, + amount_paid_out: amount, + fee_paid: 0, + new_tao_reserve: 0, + new_alpha_reserve: 0, + }), + } + } + fn approx_fee_amount(netuid: u16, amount: u64) -> u64 { Self::calculate_fee_amount(netuid.into(), amount) } From 7d6dcf55e0936c367b94ef06e8b917fbe631058f Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 20 May 2025 16:47:53 +0200 Subject: [PATCH 3/7] Add RPC for current alpha price --- Cargo.lock | 29 +++++++ Cargo.toml | 2 + node/Cargo.toml | 2 + node/src/rpc.rs | 4 + pallets/subtensor/src/staking/stake_utils.rs | 7 +- pallets/swap-interface/src/lib.rs | 6 +- pallets/swap/Cargo.toml | 2 + pallets/swap/rpc/Cargo.toml | 24 ++++++ pallets/swap/rpc/src/lib.rs | 79 ++++++++++++++++++++ pallets/swap/runtime-api/Cargo.toml | 22 ++++++ pallets/swap/runtime-api/src/lib.rs | 9 +++ pallets/swap/src/pallet/impls.rs | 34 +++++---- runtime/Cargo.toml | 4 + runtime/src/lib.rs | 6 ++ 14 files changed, 207 insertions(+), 23 deletions(-) create mode 100644 pallets/swap/rpc/Cargo.toml create mode 100644 pallets/swap/rpc/src/lib.rs create mode 100644 pallets/swap/runtime-api/Cargo.toml create mode 100644 pallets/swap/runtime-api/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index f04d84623b..00dcf72db7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5932,6 +5932,8 @@ dependencies = [ "num-traits", "pallet-commitments", "pallet-drand", + "pallet-subtensor-swap-rpc", + "pallet-subtensor-swap-runtime-api", "pallet-transaction-payment", "pallet-transaction-payment-rpc", "pallet-transaction-payment-rpc-runtime-api", @@ -6032,6 +6034,7 @@ dependencies = [ "pallet-scheduler", "pallet-subtensor", "pallet-subtensor-swap", + "pallet-subtensor-swap-runtime-api", "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", @@ -6059,6 +6062,7 @@ dependencies = [ "sp-tracing 17.0.1", "sp-transaction-pool", "sp-version", + "substrate-fixed", "substrate-wasm-builder", "subtensor-custom-rpc-runtime-api", "subtensor-macros", @@ -6890,6 +6894,7 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", + "pallet-subtensor-swap-runtime-api", "parity-scale-codec", "safe-math", "scale-info", @@ -6904,6 +6909,30 @@ dependencies = [ "subtensor-swap-interface", ] +[[package]] +name = "pallet-subtensor-swap-rpc" +version = "1.0.0" +dependencies = [ + "jsonrpsee", + "pallet-subtensor-swap-runtime-api", + "parity-scale-codec", + "sp-api", + "sp-blockchain", + "sp-runtime", + "substrate-fixed", +] + +[[package]] +name = "pallet-subtensor-swap-runtime-api" +version = "1.0.0" +dependencies = [ + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409)", + "substrate-fixed", +] + [[package]] name = "pallet-sudo" version = "38.0.0" diff --git a/Cargo.toml b/Cargo.toml index 747d3a9c17..e56b5f1951 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,6 +52,8 @@ pallet-commitments = { default-features = false, path = "pallets/commitments" } pallet-registry = { default-features = false, path = "pallets/registry" } pallet-subtensor = { default-features = false, path = "pallets/subtensor" } pallet-subtensor-swap = { default-features = false, path = "pallets/swap" } +pallet-subtensor-swap-runtime-api = { default-features = false, path = "pallets/swap/runtime-api" } +pallet-subtensor-swap-rpc = { default-features = false, path = "pallets/swap/rpc" } safe-math = { default-features = false, path = "primitives/safe-math" } subtensor-custom-rpc = { default-features = false, path = "pallets/subtensor/rpc" } subtensor-custom-rpc-runtime-api = { default-features = false, path = "pallets/subtensor/runtime-api" } diff --git a/node/Cargo.toml b/node/Cargo.toml index 6cea8f6950..54be202dc5 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -109,6 +109,8 @@ node-subtensor-runtime = { workspace = true, features = ["std"] } subtensor-runtime-common = { workspace = true, features = ["std"] } subtensor-custom-rpc = { workspace = true, features = ["std"] } subtensor-custom-rpc-runtime-api = { workspace = true, features = ["std"] } +pallet-subtensor-swap-rpc = { workspace = true, features = ["std"] } +pallet-subtensor-swap-runtime-api = { workspace = true, features = ["std"] } [build-dependencies] substrate-build-script-utils = { workspace = true } diff --git a/node/src/rpc.rs b/node/src/rpc.rs index 0d4cd355de..a14a01ebbc 100644 --- a/node/src/rpc.rs +++ b/node/src/rpc.rs @@ -111,6 +111,7 @@ where CIDP: CreateInherentDataProviders + Send + Clone + 'static, CT: fp_rpc::ConvertTransaction<::Extrinsic> + Send + Sync + Clone + 'static, { + use pallet_subtensor_swap_rpc::{Swap, SwapRpcApiServer}; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; use sc_consensus_manual_seal::rpc::{ManualSeal, ManualSealApiServer}; use substrate_frame_rpc_system::{System, SystemApiServer}; @@ -127,6 +128,9 @@ where // Custom RPC methods for Paratensor module.merge(SubtensorCustom::new(client.clone()).into_rpc())?; + // Swap RPC + module.merge(Swap::new(client.clone()).into_rpc())?; + module.merge(System::new(client.clone(), pool.clone()).into_rpc())?; module.merge(TransactionPayment::new(client).into_rpc())?; diff --git a/pallets/subtensor/src/staking/stake_utils.rs b/pallets/subtensor/src/staking/stake_utils.rs index 4495e521c8..af5a08d1a3 100644 --- a/pallets/subtensor/src/staking/stake_utils.rs +++ b/pallets/subtensor/src/staking/stake_utils.rs @@ -980,9 +980,10 @@ impl Pallet { ); // Ensure that the stake amount to be removed is above the minimum in tao equivalent. - let tao_equivalent = T::SwapInterface::sim_swap(origin_netuid, OrderType::Sell, alpha_amount) - .map(|res| res.amount_paid_out) - .map_err(|_| Error::::InsufficientLiquidity)?; + let tao_equivalent = + T::SwapInterface::sim_swap(origin_netuid, OrderType::Sell, alpha_amount) + .map(|res| res.amount_paid_out) + .map_err(|_| Error::::InsufficientLiquidity)?; ensure!( tao_equivalent > DefaultMinStake::::get(), Error::::AmountTooLow diff --git a/pallets/swap-interface/src/lib.rs b/pallets/swap-interface/src/lib.rs index 5f6213e534..c4735d7050 100644 --- a/pallets/swap-interface/src/lib.rs +++ b/pallets/swap-interface/src/lib.rs @@ -17,11 +17,7 @@ pub trait SwapHandler { price_limit: u64, should_rollback: bool, ) -> Result; - fn sim_swap( - netuid: u16, - order_t: OrderType, - amount: u64, - ) -> Result; + fn sim_swap(netuid: u16, order_t: OrderType, amount: u64) -> Result; fn approx_fee_amount(netuid: u16, amount: u64) -> u64; fn current_alpha_price(netuid: u16) -> U96F32; fn max_price() -> u64; diff --git a/pallets/swap/Cargo.toml b/pallets/swap/Cargo.toml index 7be8c6aa6f..eca30d7b29 100644 --- a/pallets/swap/Cargo.toml +++ b/pallets/swap/Cargo.toml @@ -20,6 +20,7 @@ sp-runtime = { workspace = true } sp-std = { workspace = true } substrate-fixed = { workspace = true } +pallet-subtensor-swap-runtime-api = { workspace = true } subtensor-swap-interface = { workspace = true } subtensor-macros = { workspace = true } @@ -34,6 +35,7 @@ std = [ "frame-benchmarking/std", "frame-support/std", "frame-system/std", + "pallet-subtensor-swap-runtime-api/std", "safe-math/std", "scale-info/std", "serde/std", diff --git a/pallets/swap/rpc/Cargo.toml b/pallets/swap/rpc/Cargo.toml new file mode 100644 index 0000000000..944c425335 --- /dev/null +++ b/pallets/swap/rpc/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "pallet-subtensor-swap-rpc" +version = "1.0.0" +description = "RPC interface for the Swap pallet" +edition = { workspace = true } + +[dependencies] +codec = { workspace = true } +jsonrpsee = { workspace = true } +sp-api = { workspace = true } +sp-blockchain = { workspace = true } +sp-runtime = { workspace = true } +pallet-subtensor-swap-runtime-api = { workspace = true } +substrate-fixed = { workspace = true } + +[features] +default = ["std"] +std = [ + "codec/std", + "pallet-subtensor-swap-runtime-api/std", + "sp-api/std", + "sp-runtime/std", + "substrate-fixed/std", +] diff --git a/pallets/swap/rpc/src/lib.rs b/pallets/swap/rpc/src/lib.rs new file mode 100644 index 0000000000..bb44371788 --- /dev/null +++ b/pallets/swap/rpc/src/lib.rs @@ -0,0 +1,79 @@ +//! RPC interface for the Swap pallet + +use std::sync::Arc; + +use jsonrpsee::{ + core::RpcResult, + proc_macros::rpc, + types::{ErrorObjectOwned, error::ErrorObject}, +}; +use sp_api::ProvideRuntimeApi; +use sp_blockchain::HeaderBackend; +use sp_runtime::traits::Block as BlockT; +use substrate_fixed::types::U96F32; + +pub use pallet_subtensor_swap_runtime_api::SwapRuntimeApi; + +#[rpc(client, server)] +pub trait SwapRpcApi { + #[method(name = "swap_currentAlphaPrice")] + fn current_alpha_price(&self, netuid: u16, at: Option) -> RpcResult; +} + +/// Error type of this RPC api. +pub enum Error { + /// The call to runtime failed. + RuntimeError(String), +} + +impl From for ErrorObjectOwned { + fn from(e: Error) -> Self { + match e { + Error::RuntimeError(e) => ErrorObject::owned(1, e, None::<()>), + } + } +} + +impl From for i32 { + fn from(e: Error) -> i32 { + match e { + Error::RuntimeError(_) => 1, + } + } +} + +/// Swap RPC implementation. +pub struct Swap { + client: Arc, + _marker: std::marker::PhantomData, +} + +impl Swap { + /// Create new `Swap` instance with the given reference to the client. + pub fn new(client: Arc) -> Self { + Self { + client, + _marker: Default::default(), + } + } +} + +impl SwapRpcApiServer<::Hash> for Swap +where + Block: BlockT, + C: ProvideRuntimeApi + HeaderBackend + Send + Sync + 'static, + C::Api: SwapRuntimeApi, +{ + fn current_alpha_price( + &self, + netuid: u16, + at: Option<::Hash>, + ) -> RpcResult { + let api = self.client.runtime_api(); + let at = at.unwrap_or_else(|| self.client.info().best_hash); + + api.current_alpha_price(at, netuid).map_err(|e| { + Error::RuntimeError(format!("Unable to get current alpha price: {:?}", e)).into() + }) + } +} diff --git a/pallets/swap/runtime-api/Cargo.toml b/pallets/swap/runtime-api/Cargo.toml new file mode 100644 index 0000000000..0a3da77ab2 --- /dev/null +++ b/pallets/swap/runtime-api/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "pallet-subtensor-swap-runtime-api" +version = "1.0.0" +description = "Runtime API for the Swap pallet" +edition = { workspace = true } + +[dependencies] +codec = { workspace = true } +scale-info = { workspace = true } +substrate-fixed = { workspace = true } +sp-api = { workspace = true } +sp-std = { workspace = true } + +[features] +default = ["std"] +std = [ + "codec/std", + "scale-info/std", + "sp-api/std", + "sp-std/std", + "substrate-fixed/std", +] diff --git a/pallets/swap/runtime-api/src/lib.rs b/pallets/swap/runtime-api/src/lib.rs new file mode 100644 index 0000000000..402b210613 --- /dev/null +++ b/pallets/swap/runtime-api/src/lib.rs @@ -0,0 +1,9 @@ +#![cfg_attr(not(feature = "std"), no_std)] + +use substrate_fixed::types::U96F32; + +sp_api::decl_runtime_apis! { + pub trait SwapRuntimeApi { + fn current_alpha_price(netuid: u16) -> U96F32; + } +} diff --git a/pallets/swap/src/pallet/impls.rs b/pallets/swap/src/pallet/impls.rs index a70c23f1c3..e7e9044f5a 100644 --- a/pallets/swap/src/pallet/impls.rs +++ b/pallets/swap/src/pallet/impls.rs @@ -241,6 +241,24 @@ impl SwapStep { } impl Pallet { + pub fn current_price(netuid: NetUid) -> U96F32 { + match T::SubnetInfo::mechanism(netuid.into()) { + 1 => { + let sqrt_price = AlphaSqrtPrice::::get(NetUid::from(netuid)); + let tao_reserve = T::SubnetInfo::tao_reserve(netuid.into()); + let alpha_reserve = T::SubnetInfo::alpha_reserve(netuid.into()); + + if sqrt_price == 0 && tao_reserve > 0 && alpha_reserve > 0 { + U96F32::saturating_from_num(tao_reserve) + .saturating_div(U96F32::saturating_from_num(alpha_reserve)) + } else { + U96F32::saturating_from_num(sqrt_price.saturating_mul(sqrt_price)) + } + } + _ => U96F32::saturating_from_num(1), + } + } + // initializes V3 swap for a subnet if needed fn maybe_initialize_v3(netuid: NetUid) -> Result<(), Error> { if SwapV3Initialized::::get(netuid) { @@ -1080,21 +1098,7 @@ impl SwapHandler for Pallet { } fn current_alpha_price(netuid: u16) -> U96F32 { - match T::SubnetInfo::mechanism(netuid) { - 1 => { - let sqrt_price = AlphaSqrtPrice::::get(NetUid::from(netuid)); - let tao_reserve = T::SubnetInfo::tao_reserve(netuid); - let alpha_reserve = T::SubnetInfo::alpha_reserve(netuid); - - if sqrt_price == 0 && tao_reserve > 0 && alpha_reserve > 0 { - U96F32::saturating_from_num(tao_reserve) - .saturating_div(U96F32::saturating_from_num(alpha_reserve)) - } else { - U96F32::saturating_from_num(sqrt_price.saturating_mul(sqrt_price)) - } - } - _ => U96F32::saturating_from_num(1), - } + Self::current_price(netuid.into()) } fn min_price() -> u64 { diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index a1e26e5ac3..099e24ad7a 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -33,6 +33,8 @@ pallet-aura = { workspace = true } pallet-balances = { workspace = true } pallet-subtensor = { workspace = true } pallet-subtensor-swap = { workspace = true } +pallet-subtensor-swap-runtime-api = { workspace = true } +substrate-fixed = { workspace = true } subtensor-swap-interface = { workspace = true } frame-support = { workspace = true } pallet-grandpa = { workspace = true } @@ -153,6 +155,8 @@ std = [ "frame-try-runtime/std", "pallet-subtensor/std", "pallet-subtensor-swap/std", + "pallet-subtensor-swap-runtime-api/std", + "substrate-fixed/std", "subtensor-swap-interface/std", "pallet-aura/std", "pallet-balances/std", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index e037f31d76..a5f3fc0b90 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -2140,6 +2140,12 @@ impl_runtime_apis! { SubtensorModule::get_network_lock_cost() } } + + impl pallet_subtensor_swap_runtime_api::SwapRuntimeApi for Runtime { + fn current_alpha_price(netuid: u16) -> substrate_fixed::types::U96F32 { + pallet_subtensor_swap::Pallet::::current_price(netuid.into()) + } + } } #[test] From b0af896b3d63618c6d8ddcad24a9c9f163568fe0 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 20 May 2025 19:01:31 +0200 Subject: [PATCH 4/7] Reformat --- pallets/subtensor/src/tests/staking.rs | 2 +- pallets/swap/src/benchmarking.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/subtensor/src/tests/staking.rs b/pallets/subtensor/src/tests/staking.rs index a40979439a..ca942bf049 100644 --- a/pallets/subtensor/src/tests/staking.rs +++ b/pallets/subtensor/src/tests/staking.rs @@ -2762,7 +2762,7 @@ fn test_unstake_low_liquidity_validate() { let subnet_owner_hotkey = U256::from(1002); let hotkey = U256::from(2); let coldkey = U256::from(3); - let amount_staked = DefaultMinStake::::get() * 10 + 0; // FIXME: DefaultStakingFee is deprecated + let amount_staked = DefaultMinStake::::get() * 10; // FIXME: DefaultStakingFee is deprecated let netuid = add_dynamic_network(&subnet_owner_hotkey, &subnet_owner_coldkey); SubtensorModule::create_account_if_non_existent(&coldkey, &hotkey); diff --git a/pallets/swap/src/benchmarking.rs b/pallets/swap/src/benchmarking.rs index 133a0ef5bc..e39d9cf7e7 100644 --- a/pallets/swap/src/benchmarking.rs +++ b/pallets/swap/src/benchmarking.rs @@ -106,7 +106,7 @@ mod benchmarks { (netuid, caller.clone(), id), Position { id, - netuid: netuid, + netuid, tick_low: TickIndex::new(-10000).unwrap(), tick_high: TickIndex::new(10000).unwrap(), liquidity: 10000, From 2b50e6889b3b079b48a9723e3044b1292692aee3 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Tue, 20 May 2025 19:19:34 +0200 Subject: [PATCH 5/7] Change current price to u64 in RPC --- Cargo.lock | 2 -- pallets/swap/rpc/Cargo.toml | 2 -- pallets/swap/rpc/src/lib.rs | 5 ++--- pallets/swap/runtime-api/Cargo.toml | 2 -- pallets/swap/runtime-api/src/lib.rs | 4 +--- pallets/swap/src/benchmarking.rs | 4 ++-- runtime/src/lib.rs | 10 ++++++++-- 7 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 00dcf72db7..f72955a4de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6919,7 +6919,6 @@ dependencies = [ "sp-api", "sp-blockchain", "sp-runtime", - "substrate-fixed", ] [[package]] @@ -6930,7 +6929,6 @@ dependencies = [ "scale-info", "sp-api", "sp-std 14.0.0 (git+https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-stable2409)", - "substrate-fixed", ] [[package]] diff --git a/pallets/swap/rpc/Cargo.toml b/pallets/swap/rpc/Cargo.toml index 944c425335..cc5fbc9067 100644 --- a/pallets/swap/rpc/Cargo.toml +++ b/pallets/swap/rpc/Cargo.toml @@ -11,7 +11,6 @@ sp-api = { workspace = true } sp-blockchain = { workspace = true } sp-runtime = { workspace = true } pallet-subtensor-swap-runtime-api = { workspace = true } -substrate-fixed = { workspace = true } [features] default = ["std"] @@ -20,5 +19,4 @@ std = [ "pallet-subtensor-swap-runtime-api/std", "sp-api/std", "sp-runtime/std", - "substrate-fixed/std", ] diff --git a/pallets/swap/rpc/src/lib.rs b/pallets/swap/rpc/src/lib.rs index bb44371788..e8fa85493d 100644 --- a/pallets/swap/rpc/src/lib.rs +++ b/pallets/swap/rpc/src/lib.rs @@ -10,14 +10,13 @@ use jsonrpsee::{ use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; use sp_runtime::traits::Block as BlockT; -use substrate_fixed::types::U96F32; pub use pallet_subtensor_swap_runtime_api::SwapRuntimeApi; #[rpc(client, server)] pub trait SwapRpcApi { #[method(name = "swap_currentAlphaPrice")] - fn current_alpha_price(&self, netuid: u16, at: Option) -> RpcResult; + fn current_alpha_price(&self, netuid: u16, at: Option) -> RpcResult; } /// Error type of this RPC api. @@ -68,7 +67,7 @@ where &self, netuid: u16, at: Option<::Hash>, - ) -> RpcResult { + ) -> RpcResult { let api = self.client.runtime_api(); let at = at.unwrap_or_else(|| self.client.info().best_hash); diff --git a/pallets/swap/runtime-api/Cargo.toml b/pallets/swap/runtime-api/Cargo.toml index 0a3da77ab2..d871adb651 100644 --- a/pallets/swap/runtime-api/Cargo.toml +++ b/pallets/swap/runtime-api/Cargo.toml @@ -7,7 +7,6 @@ edition = { workspace = true } [dependencies] codec = { workspace = true } scale-info = { workspace = true } -substrate-fixed = { workspace = true } sp-api = { workspace = true } sp-std = { workspace = true } @@ -18,5 +17,4 @@ std = [ "scale-info/std", "sp-api/std", "sp-std/std", - "substrate-fixed/std", ] diff --git a/pallets/swap/runtime-api/src/lib.rs b/pallets/swap/runtime-api/src/lib.rs index 402b210613..5db91a5a26 100644 --- a/pallets/swap/runtime-api/src/lib.rs +++ b/pallets/swap/runtime-api/src/lib.rs @@ -1,9 +1,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use substrate_fixed::types::U96F32; - sp_api::decl_runtime_apis! { pub trait SwapRuntimeApi { - fn current_alpha_price(netuid: u16) -> U96F32; + fn current_alpha_price(netuid: u16) -> u64; } } diff --git a/pallets/swap/src/benchmarking.rs b/pallets/swap/src/benchmarking.rs index e39d9cf7e7..6f3327d00e 100644 --- a/pallets/swap/src/benchmarking.rs +++ b/pallets/swap/src/benchmarking.rs @@ -1,6 +1,6 @@ //! Benchmarking setup for pallet-subtensor-swap -#![cfg(feature = "runtime-benchmarks")] -#![allow(clippy::arithmetic_side_effects)] +#![allow(clippy::unwrap_used)] +#![allow(clippy::multiple_bound_locations)] use frame_benchmarking::v2::*; use frame_support::traits::Get; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index a5f3fc0b90..c89c075bc1 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1125,7 +1125,8 @@ parameter_types! { pub const SwapMaxFeeRate: u16 = 10000; // 15.26% pub const SwapMaxPositions: u32 = 100; pub const SwapMinimumLiquidity: u64 = 1_000; - pub const SwapMinimumReserve: NonZeroU64 = NonZeroU64::new(1_000_000).unwrap(); + pub const SwapMinimumReserve: NonZeroU64 = NonZeroU64::new(1_000_000) + .expect("1_000_000 fits NonZeroU64"); } impl pallet_subtensor_swap::Config for Runtime { @@ -2141,9 +2142,14 @@ impl_runtime_apis! { } } + impl pallet_subtensor_swap_runtime_api::SwapRuntimeApi for Runtime { - fn current_alpha_price(netuid: u16) -> substrate_fixed::types::U96F32 { + fn current_alpha_price(netuid: u16) -> u64 { + use substrate_fixed::types::U96F32; + pallet_subtensor_swap::Pallet::::current_price(netuid.into()) + .saturating_mul(U96F32::from_num(1_000_000_000)) + .saturating_to_num() } } } From 67a592275ab21f13b3b5e06cf8f8c10e875ee368 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 21 May 2025 17:10:24 +0200 Subject: [PATCH 6/7] Fix clippy --- pallets/subtensor/src/tests/move_stake.rs | 2 ++ pallets/subtensor/src/tests/staking2.rs | 2 ++ pallets/swap/src/mock.rs | 2 ++ pallets/swap/src/pallet/impls.rs | 3 +++ pallets/swap/src/tick.rs | 1 + 5 files changed, 10 insertions(+) diff --git a/pallets/subtensor/src/tests/move_stake.rs b/pallets/subtensor/src/tests/move_stake.rs index 30186c3300..2264453a4d 100644 --- a/pallets/subtensor/src/tests/move_stake.rs +++ b/pallets/subtensor/src/tests/move_stake.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unwrap_used)] + use approx::assert_abs_diff_eq; use frame_support::{assert_err, assert_noop, assert_ok}; use sp_core::{Get, U256}; diff --git a/pallets/subtensor/src/tests/staking2.rs b/pallets/subtensor/src/tests/staking2.rs index aaf57b2e7b..e5bc16dd0a 100644 --- a/pallets/subtensor/src/tests/staking2.rs +++ b/pallets/subtensor/src/tests/staking2.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unwrap_used)] + use frame_support::{ assert_ok, dispatch::{GetDispatchInfo, Pays}, diff --git a/pallets/swap/src/mock.rs b/pallets/swap/src/mock.rs index e30c1978cc..e439f5be67 100644 --- a/pallets/swap/src/mock.rs +++ b/pallets/swap/src/mock.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unwrap_used)] + use core::num::NonZeroU64; use frame_support::construct_runtime; diff --git a/pallets/swap/src/pallet/impls.rs b/pallets/swap/src/pallet/impls.rs index e7e9044f5a..e3c7b3a4ed 100644 --- a/pallets/swap/src/pallet/impls.rs +++ b/pallets/swap/src/pallet/impls.rs @@ -1132,6 +1132,9 @@ pub enum SwapStepAction { } // cargo test --package pallet-subtensor-swap --lib -- pallet::impls::tests --show-output +#[allow(clippy::unwrap_used)] +#[allow(clippy::indexing_slicing)] +#[allow(clippy::arithmetic_side_effects)] #[cfg(test)] mod tests { use approx::assert_abs_diff_eq; diff --git a/pallets/swap/src/tick.rs b/pallets/swap/src/tick.rs index 5d85fe1b6e..667764f63b 100644 --- a/pallets/swap/src/tick.rs +++ b/pallets/swap/src/tick.rs @@ -1202,6 +1202,7 @@ impl fmt::Display for TickMathError { impl Error for TickMathError {} +#[allow(clippy::unwrap_used)] #[cfg(test)] mod tests { use safe_math::FixedExt; From dac63e4c17f0fd5ef16055b9756702da650f69e5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Tsurko Date: Wed, 21 May 2025 17:16:33 +0200 Subject: [PATCH 7/7] Fix zepter --- pallets/admin-utils/Cargo.toml | 4 +++- pallets/swap/Cargo.toml | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pallets/admin-utils/Cargo.toml b/pallets/admin-utils/Cargo.toml index 8c150a7e60..1390a2da13 100644 --- a/pallets/admin-utils/Cargo.toml +++ b/pallets/admin-utils/Cargo.toml @@ -58,6 +58,7 @@ std = [ "pallet-evm-chain-id/std", "pallet-grandpa/std", "pallet-scheduler/std", + "pallet-subtensor-swap/std", "pallet-subtensor/std", "scale-info/std", "sp-consensus-aura/std", @@ -69,7 +70,7 @@ std = [ "sp-tracing/std", "sp-weights/std", "substrate-fixed/std", - "pallet-subtensor-swap/std", + "subtensor-swap-interface/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -80,6 +81,7 @@ runtime-benchmarks = [ "pallet-grandpa/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", "pallet-subtensor/runtime-benchmarks", + "pallet-subtensor-swap/runtime-benchmarks", "sp-runtime/runtime-benchmarks", ] try-runtime = [ diff --git a/pallets/swap/Cargo.toml b/pallets/swap/Cargo.toml index eca30d7b29..df7ee91686 100644 --- a/pallets/swap/Cargo.toml +++ b/pallets/swap/Cargo.toml @@ -51,4 +51,5 @@ runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", ]