Skip to content

Commit 344e37a

Browse files
committed
use appropriate types (NetUid and TaoCurrency) in sim_swap_tao_for_alpha
1 parent 57d60c6 commit 344e37a

File tree

6 files changed

+26
-19
lines changed

6 files changed

+26
-19
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pallets/swap/rpc/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ sp-api.workspace = true
1111
sp-blockchain.workspace = true
1212
sp-runtime.workspace = true
1313
pallet-subtensor-swap-runtime-api.workspace = true
14+
subtensor-runtime-common = { workspace = true, default-features = false }
1415
subtensor-swap-interface.workspace = true
1516

1617
[features]
@@ -20,5 +21,6 @@ std = [
2021
"pallet-subtensor-swap-runtime-api/std",
2122
"sp-api/std",
2223
"sp-runtime/std",
24+
"subtensor-runtime-common/std",
2325
"subtensor-swap-interface/std",
2426
]

pallets/swap/rpc/src/lib.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,26 @@ use jsonrpsee::{
1111
use sp_api::ProvideRuntimeApi;
1212
use sp_blockchain::HeaderBackend;
1313
use sp_runtime::traits::Block as BlockT;
14+
use subtensor_runtime_common::{AlphaCurrency, NetUid, TaoCurrency};
1415

1516
pub use pallet_subtensor_swap_runtime_api::SwapRuntimeApi;
1617

1718
#[rpc(client, server)]
1819
pub trait SwapRpcApi<BlockHash> {
1920
#[method(name = "swap_currentAlphaPrice")]
20-
fn current_alpha_price(&self, netuid: u16, at: Option<BlockHash>) -> RpcResult<u64>;
21+
fn current_alpha_price(&self, netuid: NetUid, at: Option<BlockHash>) -> RpcResult<u64>;
2122
#[method(name = "swap_simSwapTaoForAlpha")]
2223
fn sim_swap_tao_for_alpha(
2324
&self,
24-
netuid: u16,
25-
tao: u64,
25+
netuid: NetUid,
26+
tao: TaoCurrency,
2627
at: Option<BlockHash>,
2728
) -> RpcResult<Vec<u8>>;
2829
#[method(name = "swap_simSwapAlphaForTao")]
2930
fn sim_swap_alpha_for_tao(
3031
&self,
31-
netuid: u16,
32-
alpha: u64,
32+
netuid: NetUid,
33+
alpha: AlphaCurrency,
3334
at: Option<BlockHash>,
3435
) -> RpcResult<Vec<u8>>;
3536
}
@@ -80,7 +81,7 @@ where
8081
{
8182
fn current_alpha_price(
8283
&self,
83-
netuid: u16,
84+
netuid: NetUid,
8485
at: Option<<Block as BlockT>::Hash>,
8586
) -> RpcResult<u64> {
8687
let api = self.client.runtime_api();
@@ -93,8 +94,8 @@ where
9394

9495
fn sim_swap_tao_for_alpha(
9596
&self,
96-
netuid: u16,
97-
tao: u64,
97+
netuid: NetUid,
98+
tao: TaoCurrency,
9899
at: Option<<Block as BlockT>::Hash>,
99100
) -> RpcResult<Vec<u8>> {
100101
let api = self.client.runtime_api();
@@ -111,8 +112,8 @@ where
111112

112113
fn sim_swap_alpha_for_tao(
113114
&self,
114-
netuid: u16,
115-
alpha: u64,
115+
netuid: NetUid,
116+
alpha: AlphaCurrency,
116117
at: Option<<Block as BlockT>::Hash>,
117118
) -> RpcResult<Vec<u8>> {
118119
let api = self.client.runtime_api();

pallets/swap/runtime-api/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ codec = { workspace = true, features = ["derive"] }
99
scale-info.workspace = true
1010
sp-api.workspace = true
1111
sp-std.workspace = true
12+
subtensor-runtime-common = { workspace = true, default-features = false }
1213
subtensor-swap-interface.workspace = true
1314

1415
[features]
1516
default = ["std"]
16-
std = ["codec/std", "scale-info/std", "sp-api/std", "sp-std/std", "subtensor-swap-interface/std"]
17+
std = ["codec/std", "scale-info/std", "sp-api/std", "sp-std/std", "subtensor-runtime-common/std", "subtensor-swap-interface/std"]
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#![cfg_attr(not(feature = "std"), no_std)]
22

3+
use subtensor_runtime_common::{AlphaCurrency, NetUid, TaoCurrency};
34
use subtensor_swap_interface::SwapResult;
45

56
sp_api::decl_runtime_apis! {
67
pub trait SwapRuntimeApi {
7-
fn current_alpha_price(netuid: u16) -> u64;
8-
fn sim_swap_tao_for_alpha(netuid: u16, tao: u64) -> SwapResult;
9-
fn sim_swap_alpha_for_tao(netuid: u16, alpha: u64) -> SwapResult;
8+
fn current_alpha_price(netuid: NetUid) -> u64;
9+
fn sim_swap_tao_for_alpha(netuid: NetUid, tao: TaoCurrency) -> SwapResult;
10+
fn sim_swap_alpha_for_tao(netuid: NetUid, alpha: AlphaCurrency) -> SwapResult;
1011
}
1112
}

runtime/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,19 +2409,19 @@ impl_runtime_apis! {
24092409
}
24102410

24112411
impl pallet_subtensor_swap_runtime_api::SwapRuntimeApi<Block> for Runtime {
2412-
fn current_alpha_price(netuid: u16) -> u64 {
2412+
fn current_alpha_price(netuid: NetUid) -> u64 {
24132413
use substrate_fixed::types::U96F32;
24142414

24152415
pallet_subtensor_swap::Pallet::<Runtime>::current_price(netuid.into())
24162416
.saturating_mul(U96F32::from_num(1_000_000_000))
24172417
.saturating_to_num()
24182418
}
24192419

2420-
fn sim_swap_tao_for_alpha(netuid: u16, tao: u64) -> SwapResult {
2420+
fn sim_swap_tao_for_alpha(netuid: NetUid, tao: TaoCurrency) -> SwapResult {
24212421
pallet_subtensor_swap::Pallet::<Runtime>::sim_swap(
24222422
netuid.into(),
24232423
OrderType::Buy,
2424-
tao,
2424+
tao.into(),
24252425
).unwrap_or(SwapResult {
24262426
amount_paid_in: 0,
24272427
amount_paid_out: 0,
@@ -2431,11 +2431,11 @@ impl_runtime_apis! {
24312431
})
24322432
}
24332433

2434-
fn sim_swap_alpha_for_tao(netuid: u16, alpha: u64) -> SwapResult {
2434+
fn sim_swap_alpha_for_tao(netuid: NetUid, alpha: AlphaCurrency) -> SwapResult {
24352435
pallet_subtensor_swap::Pallet::<Runtime>::sim_swap(
24362436
netuid.into(),
24372437
OrderType::Sell,
2438-
alpha,
2438+
alpha.into(),
24392439
).unwrap_or(SwapResult {
24402440
amount_paid_in: 0,
24412441
amount_paid_out: 0,

0 commit comments

Comments
 (0)