Skip to content

Commit 3eb55e5

Browse files
committed
Merge branch 'devnet-ready' into mevshield-dynmaic-tx-construction
2 parents 92b7c04 + 8a8a5cb commit 3eb55e5

File tree

7 files changed

+18
-47
lines changed

7 files changed

+18
-47
lines changed

Cargo.lock

Lines changed: 1 addition & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ sp-keystore = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "p
274274
w3f-bls = { git = "https://github.com/opentensor/bls", branch = "fix-no-std", default-features = false }
275275
ark-crypto-primitives = { version = "0.4.0", default-features = false }
276276
ark-scale = { version = "0.0.11", default-features = false }
277-
sp-ark-bls12-381 = { git = "https://github.com/paritytech/arkworks-substrate", package = "sp-ark-bls12-381", default-features = false }
278277
ark-bls12-381 = { version = "0.4.0", default-features = false }
279278
ark-serialize = { version = "0.4.0", default-features = false }
280279
ark-ff = { version = "0.4.0", default-features = false }

pallets/drand/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ scale-info = { workspace = true, features = ["derive"] }
1717
serde = { workspace = true, features = ["derive"] }
1818
serde_json.workspace = true
1919
log.workspace = true
20-
hex = { workspace = true, features = ["serde"] }
20+
hex = { workspace = true, features = ["serde", "alloc"] }
2121
sha2.workspace = true
2222
anyhow.workspace = true
2323
# frame deps
@@ -29,7 +29,7 @@ sp-io.workspace = true
2929
sp-runtime.workspace = true
3030
sp-std.workspace = true
3131
# arkworks dependencies
32-
sp-ark-bls12-381.workspace = true
32+
sp-crypto-ec-utils = { workspace = true, features = ["bls12-381"] }
3333
ark-bls12-381 = { workspace = true, features = ["curve"] }
3434
ark-serialize = { workspace = true, features = ["derive"] }
3535
ark-ff.workspace = true
@@ -64,7 +64,7 @@ std = [
6464
"serde/std",
6565
"serde_json/std",
6666
"hex/std",
67-
"sp-ark-bls12-381/std",
67+
"sp-crypto-ec-utils/std",
6868
"ark-bls12-381/std",
6969
"ark-serialize/std",
7070
"ark-ff/std",

pallets/drand/src/bls12_381.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
use ark_ec::pairing::Pairing;
1818
use ark_std::{Zero, ops::Neg};
19-
use sp_ark_bls12_381::{
19+
use sp_crypto_ec_utils::bls12_381::{
2020
Bls12_381 as Bls12_381Opt, G1Affine as G1AffineOpt, G2Affine as G2AffineOpt,
2121
};
2222

pallets/drand/src/verifier.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use ark_ec::{AffineRepr, hashing::HashToCurve};
2727
use ark_serialize::CanonicalSerialize;
2828
use codec::Decode;
2929
use sha2::{Digest, Sha256};
30-
use sp_ark_bls12_381::{G1Affine as G1AffineOpt, G2Affine as G2AffineOpt};
30+
use sp_crypto_ec_utils::bls12_381::{G1Affine as G1AffineOpt, G2Affine as G2AffineOpt};
3131
use tle::curves::drand::TinyBLS381;
3232
use w3f_bls::engine::EngineBLS;
3333

pallets/subtensor/src/staking/stake_utils.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -694,9 +694,6 @@ impl<T: Config> Pallet<T> {
694694
price_limit: TaoCurrency,
695695
drop_fees: bool,
696696
) -> Result<TaoCurrency, DispatchError> {
697-
// Record the protocol TAO before the swap.
698-
let protocol_tao = Self::get_protocol_tao(netuid);
699-
700697
// Decrease alpha on subnet
701698
let actual_alpha_decrease =
702699
Self::decrease_stake_for_hotkey_and_coldkey_on_subnet(hotkey, coldkey, netuid, alpha);
@@ -705,13 +702,6 @@ impl<T: Config> Pallet<T> {
705702
let swap_result =
706703
Self::swap_alpha_for_tao(netuid, actual_alpha_decrease, price_limit, drop_fees)?;
707704

708-
// Record the protocol TAO after the swap.
709-
let protocol_tao_after = Self::get_protocol_tao(netuid);
710-
// This should decrease as we are removing TAO from the protocol.
711-
let protocol_tao_delta: TaoCurrency = protocol_tao.saturating_sub(protocol_tao_after);
712-
// Use max to overstate the TAO flow from the protocol.
713-
let tao_flow = protocol_tao_delta.max(swap_result.amount_paid_out.into());
714-
715705
// Refund the unused alpha (in case if limit price is hit)
716706
let refund = actual_alpha_decrease.saturating_sub(
717707
swap_result
@@ -738,7 +728,7 @@ impl<T: Config> Pallet<T> {
738728
// }
739729

740730
// Record TAO outflow
741-
Self::record_tao_outflow(netuid, tao_flow);
731+
Self::record_tao_outflow(netuid, swap_result.amount_paid_out.into());
742732

743733
LastColdkeyHotkeyStakeBlock::<T>::insert(coldkey, hotkey, Self::get_current_block_as_u64());
744734

@@ -777,20 +767,9 @@ impl<T: Config> Pallet<T> {
777767
set_limit: bool,
778768
drop_fees: bool,
779769
) -> Result<AlphaCurrency, DispatchError> {
780-
// Record the protocol TAO before the swap.
781-
let protocol_tao = Self::get_protocol_tao(netuid);
782-
783770
// Swap the tao to alpha.
784771
let swap_result = Self::swap_tao_for_alpha(netuid, tao, price_limit, drop_fees)?;
785772

786-
// Record the protocol TAO after the swap.
787-
let protocol_tao_after = Self::get_protocol_tao(netuid);
788-
789-
// This should increase as we are adding TAO to the protocol.
790-
let protocol_tao_delta: TaoCurrency = protocol_tao_after.saturating_sub(protocol_tao);
791-
// Use min to understate the TAO flow into the protocol.
792-
let tao_flow = protocol_tao_delta.min(tao);
793-
794773
ensure!(
795774
!swap_result.amount_paid_out.is_zero(),
796775
Error::<T>::AmountTooLow
@@ -826,7 +805,7 @@ impl<T: Config> Pallet<T> {
826805
}
827806

828807
// Record TAO inflow
829-
Self::record_tao_inflow(netuid, tao_flow);
808+
Self::record_tao_inflow(netuid, swap_result.amount_paid_in.into());
830809

831810
LastColdkeyHotkeyStakeBlock::<T>::insert(coldkey, hotkey, Self::get_current_block_as_u64());
832811

pallets/swap/src/pallet/impls.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -880,10 +880,12 @@ impl<T: Config> Pallet<T> {
880880
// ---------------- USER: refund τ and convert α → stake ----------------
881881

882882
// 1) Refund τ principal directly.
883-
if rm.tao > TaoCurrency::ZERO {
884-
T::BalanceOps::increase_balance(&owner, rm.tao);
885-
user_refunded_tao = user_refunded_tao.saturating_add(rm.tao);
886-
T::TaoReserve::decrease_provided(netuid, rm.tao);
883+
let tao_total_from_pool: TaoCurrency = rm.tao.saturating_add(rm.fee_tao);
884+
if tao_total_from_pool > TaoCurrency::ZERO {
885+
T::BalanceOps::increase_balance(&owner, tao_total_from_pool);
886+
user_refunded_tao =
887+
user_refunded_tao.saturating_add(tao_total_from_pool);
888+
T::TaoReserve::decrease_provided(netuid, tao_total_from_pool);
887889
}
888890

889891
// 2) Stake ALL withdrawn α (principal + fees) to the best permitted validator.
@@ -967,17 +969,17 @@ impl<T: Config> Pallet<T> {
967969
Ok(rm) => {
968970
let alpha_total_from_pool: AlphaCurrency =
969971
rm.alpha.saturating_add(rm.fee_alpha);
970-
let tao = rm.tao;
972+
let tao_total_from_pool: TaoCurrency = rm.tao.saturating_add(rm.fee_tao);
971973

972-
if tao > TaoCurrency::ZERO {
973-
burned_tao = burned_tao.saturating_add(tao);
974+
if tao_total_from_pool > TaoCurrency::ZERO {
975+
burned_tao = burned_tao.saturating_add(tao_total_from_pool);
974976
}
975977
if alpha_total_from_pool > AlphaCurrency::ZERO {
976978
burned_alpha = burned_alpha.saturating_add(alpha_total_from_pool);
977979
}
978980

979981
log::debug!(
980-
"clear_protocol_liquidity: burned protocol pos: netuid={netuid:?}, pos_id={pos_id:?}, τ={tao:?}, α_total={alpha_total_from_pool:?}"
982+
"clear_protocol_liquidity: burned protocol pos: netuid={netuid:?}, pos_id={pos_id:?}, τ={tao_total_from_pool:?}, α_total={alpha_total_from_pool:?}"
981983
);
982984
}
983985
Err(e) => {

0 commit comments

Comments
 (0)