Skip to content

Commit 7812e6b

Browse files
committed
fix runtime version
2 parents 1d83e0e + 0c3ad43 commit 7812e6b

68 files changed

Lines changed: 9198 additions & 4461 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

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

Cargo.toml

Lines changed: 132 additions & 331 deletions
Large diffs are not rendered by default.

chain-extensions/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use pallet_subtensor_proxy as pallet_proxy;
1818
use pallet_subtensor_proxy::WeightInfo;
1919
use sp_runtime::{DispatchError, Weight, traits::StaticLookup};
2020
use sp_std::marker::PhantomData;
21-
use substrate_fixed::types::U64F64;
21+
use substrate_fixed::types::U96F32;
2222
use subtensor_runtime_common::{AlphaCurrency, NetUid, ProxyType, TaoCurrency};
2323
use subtensor_swap_interface::SwapHandler;
2424

@@ -520,7 +520,7 @@ where
520520
netuid.into(),
521521
);
522522

523-
let price = current_alpha_price.saturating_mul(U64F64::from_num(1_000_000_000));
523+
let price = current_alpha_price.saturating_mul(U96F32::from_num(1_000_000_000));
524524
let price: u64 = price.saturating_to_num();
525525

526526
let encoded_result = price.encode();

chain-extensions/src/mock.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ impl pallet_subtensor::Config for Test {
426426
parameter_types! {
427427
pub const SwapProtocolId: PalletId = PalletId(*b"ten/swap");
428428
pub const SwapMaxFeeRate: u16 = 10000; // 15.26%
429+
pub const SwapMaxPositions: u32 = 100;
429430
pub const SwapMinimumLiquidity: u64 = 1_000;
430431
pub const SwapMinimumReserve: NonZeroU64 = NonZeroU64::new(100).unwrap();
431432
}
@@ -437,6 +438,7 @@ impl pallet_subtensor_swap::Config for Test {
437438
type TaoReserve = TaoCurrencyReserve<Self>;
438439
type AlphaReserve = AlphaCurrencyReserve<Self>;
439440
type MaxFeeRate = SwapMaxFeeRate;
441+
type MaxPositions = SwapMaxPositions;
440442
type MinimumLiquidity = SwapMinimumLiquidity;
441443
type MinimumReserve = SwapMinimumReserve;
442444
type WeightInfo = ();

chain-extensions/src/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use pallet_subtensor::DefaultMinStake;
1010
use sp_core::Get;
1111
use sp_core::U256;
1212
use sp_runtime::DispatchError;
13-
use substrate_fixed::types::U64F64;
13+
use substrate_fixed::types::U96F32;
1414
use subtensor_runtime_common::{AlphaCurrency, Currency as CurrencyTrait, NetUid, TaoCurrency};
1515
use subtensor_swap_interface::SwapHandler;
1616

@@ -985,7 +985,7 @@ fn get_alpha_price_returns_encoded_price() {
985985
<pallet_subtensor_swap::Pallet<mock::Test> as SwapHandler>::current_alpha_price(
986986
netuid.into(),
987987
);
988-
let expected_price_scaled = expected_price.saturating_mul(U64F64::from_num(1_000_000_000));
988+
let expected_price_scaled = expected_price.saturating_mul(U96F32::from_num(1_000_000_000));
989989
let expected_price_u64: u64 = expected_price_scaled.saturating_to_num();
990990

991991
let mut env = MockEnv::new(FunctionId::GetAlphaPriceV1, caller, netuid.encode());

common/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ targets = ["x86_64-unknown-linux-gnu"]
1212

1313
[dependencies]
1414
codec = { workspace = true, features = ["derive"] }
15+
environmental.workspace = true
1516
frame-support.workspace = true
1617
scale-info.workspace = true
1718
serde.workspace = true
@@ -31,6 +32,7 @@ approx = ["dep:approx"]
3132
fast-runtime = []
3233
std = [
3334
"codec/std",
35+
"environmental/std",
3436
"frame-support/std",
3537
"scale-info/std",
3638
"serde/std",

common/src/evm_context.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
environmental::environmental!(IN_EVM: bool);
2+
3+
/// Returns `true` if the current dispatch originated from an EVM precompile.
4+
pub fn is_in_evm() -> bool {
5+
IN_EVM::with(|v| *v).unwrap_or(false)
6+
}
7+
8+
/// Executes `f` within an EVM context, making `is_in_evm()` return `true`
9+
/// for the duration of the closure. Uses `using_once` so nested calls
10+
/// reuse the already-set value instead of building a stack.
11+
pub fn with_evm_context<R>(f: impl FnOnce() -> R) -> R {
12+
IN_EVM::using_once(&mut true, f)
13+
}
14+
15+
#[cfg(test)]
16+
mod tests {
17+
use super::*;
18+
19+
#[test]
20+
fn is_in_evm_returns_false_by_default() {
21+
assert!(!is_in_evm());
22+
}
23+
24+
#[test]
25+
fn with_evm_context_sets_flag() {
26+
with_evm_context(|| {
27+
assert!(is_in_evm());
28+
});
29+
}
30+
31+
#[test]
32+
fn flag_clears_after_evm_context() {
33+
with_evm_context(|| {});
34+
assert!(!is_in_evm());
35+
}
36+
37+
#[test]
38+
fn nested_evm_context_stays_true() {
39+
with_evm_context(|| {
40+
with_evm_context(|| {
41+
assert!(is_in_evm());
42+
});
43+
// Still true after inner context exits thanks to using_once.
44+
assert!(is_in_evm());
45+
});
46+
}
47+
}

common/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ use sp_runtime::{
1515
use subtensor_macros::freeze_struct;
1616

1717
pub use currency::*;
18+
pub use evm_context::*;
1819

1920
mod currency;
21+
mod evm_context;
2022

2123
/// Balance of an account.
2224
pub type Balance = u64;

contract-tests/bittensor/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ edition = "2021"
1010
ink = { version = "5.1.1", default-features = false }
1111
parity-scale-codec = { version = "3.0.0", default-features = false }
1212
serde = { version = "1.0.228", default-features = false }
13-
subtensor-runtime-common = { path = "../../common", default-features = false }
1413
[dev-dependencies]
1514
ink_e2e = { version = "5.1.1" }
1615

@@ -23,7 +22,6 @@ std = [
2322
"ink/std",
2423
"parity-scale-codec/std",
2524
"serde/std",
26-
"subtensor-runtime-common/std",
2725
]
2826

2927
ink-as-dependency = []

0 commit comments

Comments
 (0)