Skip to content

Commit bec8360

Browse files
authored
Merge pull request #2210 from opentensor/fix-wrong-alpha-price-precompile
Fix wrong alpha price precompile
2 parents f678cdd + 8b8b230 commit bec8360

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

precompiles/src/alpha.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ where
3535
#[precompile::public("getAlphaPrice(uint16)")]
3636
#[precompile::view]
3737
fn get_alpha_price(_handle: &mut impl PrecompileHandle, netuid: u16) -> EvmResult<U256> {
38-
let price =
38+
let current_alpha_price =
3939
<pallet_subtensor_swap::Pallet<R> as SwapHandler>::current_alpha_price(netuid.into());
40+
let price = current_alpha_price.saturating_mul(U96F32::from_num(1_000_000_000));
4041
let price: SubstrateBalance = price.saturating_to_num::<u64>().into();
4142
let price_eth = <R as pallet_evm::Config>::BalanceConverter::into_evm_balance(price)
4243
.map(|amount| amount.into_u256())
@@ -48,7 +49,9 @@ where
4849
#[precompile::public("getMovingAlphaPrice(uint16)")]
4950
#[precompile::view]
5051
fn get_moving_alpha_price(_handle: &mut impl PrecompileHandle, netuid: u16) -> EvmResult<U256> {
51-
let price: U96F32 = pallet_subtensor::Pallet::<R>::get_moving_alpha_price(netuid.into());
52+
let moving_alpha_price: U96F32 =
53+
pallet_subtensor::Pallet::<R>::get_moving_alpha_price(netuid.into());
54+
let price = moving_alpha_price.saturating_mul(U96F32::from_num(1_000_000_000));
5255
let price: SubstrateBalance = price.saturating_to_num::<u64>().into();
5356
let price_eth = <R as pallet_evm::Config>::BalanceConverter::into_evm_balance(price)
5457
.map(|amount| amount.into_u256())
@@ -202,7 +205,8 @@ where
202205
}
203206
}
204207

205-
let price: SubstrateBalance = sum_alpha_price.saturating_to_num::<u64>().into();
208+
let price = sum_alpha_price.saturating_mul(U96F32::from_num(1_000_000_000));
209+
let price: SubstrateBalance = price.saturating_to_num::<u64>().into();
206210
let price_eth = <R as pallet_evm::Config>::BalanceConverter::into_evm_balance(price)
207211
.map(|amount| amount.into_u256())
208212
.ok_or(ExitError::InvalidRange)?;

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
220220
// `spec_version`, and `authoring_version` are the same between Wasm and native.
221221
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
222222
// the compatible custom types.
223-
spec_version: 346,
223+
spec_version: 347,
224224
impl_version: 1,
225225
apis: RUNTIME_API_VERSIONS,
226226
transaction_version: 1,

0 commit comments

Comments
 (0)