Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
836 commits
Select commit Hold shift + click to select a range
4cfc725
upgrade openssl
open-junius Feb 3, 2025
d75930f
Merge pull request #1222 from opentensor/fix/migration-subnet-volume
sam0x17 Feb 3, 2025
9958450
Merge pull request #1219 from opentensor/feat/slippage-safe-stake-moving
sam0x17 Feb 3, 2025
053fa0f
Merge branch 'devnet-ready' into neuron-weights-set
open-junius Feb 3, 2025
8a73400
Merge branch 'devnet-ready' into subnet-hyperparameter
open-junius Feb 3, 2025
256e7a9
fix clippy
open-junius Feb 3, 2025
7df774b
Merge branch 'devnet-ready' into fix/remove-dynamic-fee
ales-otf Feb 3, 2025
380587c
Merge branch 'devnet-ready' into feat/identity-upgrades
JohnReedV Feb 3, 2025
ea96bec
address freeze_struct
JohnReedV Feb 3, 2025
a7232b0
rename commit_reveal_period
JohnReedV Feb 3, 2025
d118c09
apply criticial openssl update to fix RUSTSEC-2025-0004 (openssl)
sam0x17 Feb 3, 2025
3f63cba
Merge pull request #1150 from opentensor/neuron-weights-set
sam0x17 Feb 3, 2025
12f483c
remove subnet_info_v3
JohnReedV Feb 3, 2025
ea136bb
address lint
JohnReedV Feb 3, 2025
5ec05d6
Merge pull request #1226 from opentensor/sam-update-openssl
sam0x17 Feb 3, 2025
f0ceef7
Merge pull request #1220 from opentensor/fix/remove-dynamic-fee
sam0x17 Feb 3, 2025
2d32d96
update register_network with identity precompile
JohnReedV Feb 3, 2025
6d483b2
fix merge commit
camfairchild Feb 3, 2025
625a3e0
Merge branch 'devnet-ready' into feat/identity-upgrades
JohnReedV Feb 3, 2025
7769812
Merge pull request #1225 from opentensor/devnet-ready
sam0x17 Feb 3, 2025
b8b5409
bump spec
camfairchild Feb 3, 2025
0d749c8
Merge pull request #1231 from opentensor/devnet
sam0x17 Feb 3, 2025
913fb1a
remove SubnetInfov3 struct
JohnReedV Feb 3, 2025
69d2b77
rename emission_values => emission_value
JohnReedV Feb 3, 2025
6766f1d
bump spec
JohnReedV Feb 3, 2025
7b68b1f
commit Cargo.lock
open-junius Feb 4, 2025
d3b97d3
safe math
open-junius Feb 4, 2025
9c74d60
commit Cargo.lock
open-junius Feb 4, 2025
2456428
merge with target branch
open-junius Feb 4, 2025
bf1bcfb
remove duplicated function
open-junius Feb 4, 2025
86e898f
Merge pull request #1227 from opentensor/feat/no-more-weird-runtime-a…
sam0x17 Feb 4, 2025
9a271fb
Merge pull request #1233 from opentensor/devnet-ready
sam0x17 Feb 4, 2025
40c8214
Merge branch 'devnet-ready' into feat/identity-upgrades
camfairchild Feb 4, 2025
0213918
use saturating math
JohnReedV Feb 4, 2025
d479346
add cleaned coinbase
Feb 4, 2025
547ca27
noclaim
Feb 4, 2025
1a2ec64
remove complexity
Feb 4, 2025
5113b04
non scaled tao emission
Feb 5, 2025
9f95dc0
bump
Feb 5, 2025
a837ef1
fix test
Feb 5, 2025
ed0b55b
Merge pull request #1237 from opentensor/non_scaled
sam0x17 Feb 5, 2025
c5e3912
Merge branch 'devnet-ready' into subnet-hyperparameter
open-junius Feb 5, 2025
d81238a
clean coinbase
Feb 5, 2025
b144f21
pre merge
Feb 5, 2025
8ec029d
Merge branch 'devnet-ready' of https://github.com/opentensor/subtenso…
Feb 5, 2025
f29c736
no tao in for non registration
Feb 5, 2025
d4e37e8
Merge pull request #1240 from opentensor/testnet
sam0x17 Feb 5, 2025
ee37f6d
move to moving prices rather than tao reserves
Feb 5, 2025
f7058a2
Merge pull request #1242 from opentensor/devnet
sam0x17 Feb 5, 2025
e252e90
price
Feb 5, 2025
b2639e7
moving alpha
Feb 5, 2025
6c946db
bump spec
JohnReedV Feb 5, 2025
ea355f2
Fix tests
gztensor Feb 5, 2025
f91e7ca
add moving price tests
Feb 5, 2025
160b773
Merge branch 'nonclaim' of https://github.com/opentensor/subtensor in…
Feb 5, 2025
e4ccdfa
add alpha in tests
Feb 5, 2025
ba80bbb
Fix all tests
gztensor Feb 5, 2025
30475f1
Merge branch 'nonclaim' of github.com:opentensor/subtensor into nonclaim
gztensor Feb 5, 2025
3eca45f
Format
gztensor Feb 5, 2025
1ffefe1
Fix unsafe math
gztensor Feb 5, 2025
8af65df
alpha tests
Feb 5, 2025
009961d
fix test
Feb 5, 2025
0e367f7
set tao weight
Feb 5, 2025
290498e
reset default staking fee
Feb 5, 2025
ab105c7
fix names
Feb 5, 2025
452dbac
add mainnet names
Feb 5, 2025
5c96afd
cargo clippy
Feb 5, 2025
bce7cc6
cargo fmt
Feb 5, 2025
8729b25
Merge branch 'devnet-ready' into nonclaim
unconst Feb 5, 2025
8c8bc16
Merge pull request #1241 from opentensor/nonclaim
sam0x17 Feb 5, 2025
ffe3cc0
Merge pull request #1205 from opentensor/feat/identity-upgrades
sam0x17 Feb 5, 2025
c6491fc
Merge pull request #1244 from opentensor/devnet-ready
sam0x17 Feb 5, 2025
c18c3be
add a global min burn and migration
camfairchild Feb 5, 2025
a4a0595
Merge pull request #1235 from opentensor/devnet
sam0x17 Feb 5, 2025
c7d8010
add more tests for root pending etc
Feb 5, 2025
6872057
Merge branch 'nonclaim' of https://github.com/opentensor/subtensor in…
Feb 5, 2025
102e6cc
alpha divs
Feb 6, 2025
4f900ca
fix test for root
Feb 6, 2025
2b8ed3a
new test root tao
Feb 6, 2025
fb4da1c
fix wrong parse function
open-junius Feb 6, 2025
2a57be4
fix test
Feb 6, 2025
ae25f59
add toggle off for transfers
Feb 6, 2025
811e7d5
Merge pull request #1246 from opentensor/hotfix-wrong-parse-account-id
sam0x17 Feb 6, 2025
33a842d
Merge branch 'feat/no-owner-dereg' into nonclaim
JohnReedV Feb 6, 2025
ecd265d
delete unused workflow file
sam0x17 Feb 6, 2025
95665f1
Merge pull request #1247 from opentensor/sam-fix-empty-workflow-file
sam0x17 Feb 6, 2025
841c913
Fix validation for transfer toggle
gztensor Feb 6, 2025
dafc7a2
Merge branch 'nonclaim' of github.com:opentensor/subtensor into nonclaim
gztensor Feb 6, 2025
913231b
Merge remote-tracking branch 'origin/devnet-ready' into nonclaim
sam0x17 Feb 6, 2025
a2969f8
Merge branch 'main' into nonclaim-into-main
camfairchild Feb 6, 2025
66f0097
remove duplicate tests
camfairchild Feb 6, 2025
c7a3238
fix subnet creation logic
Feb 6, 2025
a2016ee
Merge pull request #1250 from opentensor/nonclaim-into-main
sam0x17 Feb 6, 2025
3be3007
cargo fmt
sam0x17 Feb 6, 2025
f95153e
add new test
Feb 6, 2025
9a7f491
Merge branch 'nonclaim' of https://github.com/opentensor/subtensor in…
Feb 6, 2025
c427fac
bump spec version to 228
sam0x17 Feb 6, 2025
c28cac9
Add test test_drain_alpha_childkey_parentkey
gztensor Feb 6, 2025
eae43ff
Merge pull request #1248 from opentensor/nonclaim
sam0x17 Feb 6, 2025
d70a9a4
Merge pull request #1251 from opentensor/devnet-ready
sam0x17 Feb 6, 2025
6eaa766
Merge pull request #1252 from opentensor/devnet
sam0x17 Feb 6, 2025
78d5703
spec bump
camfairchild Feb 6, 2025
c9e8c1a
Merge branch 'devnet-ready' into feat/min-burn-static
camfairchild Feb 6, 2025
bf6896f
Merge pull request #1245 from opentensor/feat/min-burn-static
sam0x17 Feb 6, 2025
e8ffa80
Merge branch 'devnet-ready' into serve-axon-promethoeus
open-junius Feb 7, 2025
74b9f9f
merge with devnet ready
open-junius Feb 7, 2025
20b53f5
fix audit
open-junius Feb 7, 2025
1591e88
fix audit
open-junius Feb 7, 2025
8231c0b
fix contract
open-junius Feb 7, 2025
f2caf7d
fixes to the childkey emission
Feb 7, 2025
bf0583e
commit Cargo.lock
Feb 7, 2025
de64b11
cargo clippy
Feb 7, 2025
f0ee331
cargo fmt
Feb 7, 2025
61e74ac
Merge pull request #1257 from opentensor/nonclaim
unconst Feb 7, 2025
279d215
fix min lock
Feb 7, 2025
40bfebf
Merge branch 'main' into nonclaim
unconst Feb 7, 2025
fb09aa8
fmt
camfairchild Feb 7, 2025
f97a6ce
Merge remote-tracking branch 'origin/main' into testnet
sam0x17 Feb 7, 2025
812e59b
Merge remote-tracking branch 'origin/devnet' into devnet-ready
sam0x17 Feb 7, 2025
c2d0884
fix migration test
Feb 7, 2025
3d668ea
cargo fmt
Feb 7, 2025
4082646
merge
Feb 7, 2025
cdb9f56
Merge pull request #1259 from opentensor/nonclaim
sam0x17 Feb 7, 2025
0363082
fix root
Feb 7, 2025
f2eff11
cargo fmt
Feb 7, 2025
c8eeef2
Merge pull request #1261 from opentensor/nonclaim
unconst Feb 7, 2025
29b6e36
Merge pull request #1262 from opentensor/devnet-ready
sam0x17 Feb 7, 2025
a680a64
add moving price to metagraph
Feb 7, 2025
e9b8628
Merge pull request #1264 from opentensor/nonclaim
unconst Feb 7, 2025
e3635ff
use correct min burn init (#1265)
camfairchild Feb 7, 2025
540ea7f
Merge pull request #1266 from opentensor/devnet-ready
sam0x17 Feb 7, 2025
becc513
Merge pull request #1263 from opentensor/devnet
sam0x17 Feb 7, 2025
4395017
cargo update to fix cargo audit vulnerabilities
sam0x17 Feb 7, 2025
2c297fd
bump spec version
sam0x17 Feb 7, 2025
a16dbb8
Merge pull request #1267 from opentensor/sam-cargo-update-2-7-2025
sam0x17 Feb 7, 2025
58a8a8a
Merge pull request #1268 from opentensor/devnet-ready
sam0x17 Feb 7, 2025
7b93acf
Merge pull request #1269 from opentensor/devnet
sam0x17 Feb 7, 2025
3230136
moving price init from emission
Feb 7, 2025
b0bdb16
cargo fmt
Feb 7, 2025
5c27d88
bump spec version
sam0x17 Feb 7, 2025
48441d8
Merge remote-tracking branch 'origin/nonclaim' into nonclaim
sam0x17 Feb 7, 2025
22e51ee
Merge pull request #1270 from opentensor/nonclaim
sam0x17 Feb 7, 2025
551a69f
commit Cargo.lock
Feb 7, 2025
0b6dd40
cargo clippy
Feb 7, 2025
b00b5b3
cargo fmt
Feb 7, 2025
8829875
Merge branch 'nonclaim' of https://github.com/opentensor/subtensor in…
Feb 7, 2025
3226ce8
Merge pull request #1272 from opentensor/nonclaim
unconst Feb 7, 2025
d416b62
Merge pull request #1271 from opentensor/devnet-ready
sam0x17 Feb 7, 2025
a30f514
Merge pull request #1273 from opentensor/devnet
sam0x17 Feb 7, 2025
4f8d9bb
DefaultMinimumPoolLiquidity and tempos in rao migration
gztensor Feb 7, 2025
de6f5b0
Merge pull request #1274 from opentensor/fix/remove-tempo-from-rao-mi…
sam0x17 Feb 7, 2025
4ab30f5
Merge pull request #1275 from opentensor/testnet
sam0x17 Feb 7, 2025
5b8270c
Merge pull request #1276 from opentensor/devnet
sam0x17 Feb 7, 2025
19028c4
update readme of support of M series macs
qxprakash Feb 8, 2025
fd96f59
Merge pull request #1089 from opentensor/subnet-hyperparameter
sam0x17 Feb 10, 2025
0bcd855
merge devnet-ready
open-junius Feb 11, 2025
77f343f
Merge branch 'devnet-ready' into serve-axon-promethoeus
open-junius Feb 11, 2025
eed6e18
bump runtime version
open-junius Feb 11, 2025
795d366
add tao_emission to stakeinfo runtime
ibraheem-abe Feb 12, 2025
70637f2
remove call from coinbase. already in block_step
camfairchild Feb 12, 2025
ef65dc4
add negation for pow-reg-allowed
camfairchild Feb 12, 2025
a7aac95
only root can set min pow diff
camfairchild Feb 12, 2025
4fd4757
oops
camfairchild Feb 12, 2025
e538804
dont let ck-in-swap-sched move any stake/register
camfairchild Feb 12, 2025
8f197a2
add tests for validation filter
camfairchild Feb 12, 2025
5b3d4e6
add transfer stake to call nontransfer proxy filter
camfairchild Feb 12, 2025
45a67fc
also add proxy filters for new calls
camfairchild Feb 12, 2025
bf1933c
update staking priority
JohnReedV Feb 12, 2025
9dce4e7
bump spec
camfairchild Feb 12, 2025
b05e213
use get_priority_staking for all stake operations
JohnReedV Feb 12, 2025
f5d4708
bump spec
JohnReedV Feb 12, 2025
1916e1c
clippy
JohnReedV Feb 12, 2025
185841b
Remove ownership check from transition stake validation
gztensor Feb 12, 2025
3192e31
Merge pull request #1280 from opentensor/fix/include-pow-reg-disabled…
sam0x17 Feb 12, 2025
95f1f00
Merge pull request #1282 from opentensor/feat/dont-let-coldkey-in-swa…
sam0x17 Feb 12, 2025
8356aa9
Merge pull request #1279 from opentensor/feat/add-tao-emissions-to-st…
sam0x17 Feb 13, 2025
85c71ac
Merge pull request #1281 from opentensor/update-staking-priority
sam0x17 Feb 13, 2025
b378719
Merge remote-tracking branch 'origin/devnet-ready' into fix/remove-ex…
sam0x17 Feb 13, 2025
50893bd
Merge pull request #1284 from opentensor/fix/allow-all-hotkeys-to-mov…
sam0x17 Feb 13, 2025
fc49aca
Merge pull request #1283 from opentensor/fix/remove-extra-do-set-pend…
sam0x17 Feb 13, 2025
925dd85
Merge branch 'devnet-ready' into serve-axon-promethoeus
open-junius Feb 13, 2025
3fb3061
Merge pull request #1174 from opentensor/serve-axon-promethoeus
sam0x17 Feb 13, 2025
f45ae30
Merge pull request #1278 from qxprakash/update_readme
sam0x17 Feb 13, 2025
3bcf428
max the price for EMA calc at 1.0
camfairchild Feb 13, 2025
0514da3
Merge pull request #1286 from opentensor/fix/moving-alpha-price-min-one
sam0x17 Feb 13, 2025
ab37ca0
Merge pull request #1285 from opentensor/devnet-ready
sam0x17 Feb 13, 2025
8728d0a
Merge pull request #1287 from opentensor/devnet
sam0x17 Feb 13, 2025
f5f40eb
uncommitted lockfile change
sam0x17 Feb 13, 2025
a3a91ee
bump spec version
sam0x17 Feb 13, 2025
714bcd1
Merge remote-tracking branch 'origin/main' into devnet-ready
sam0x17 Feb 13, 2025
da4d692
fix merge conflicts
sam0x17 Feb 13, 2025
7adb0a2
Merge pull request #1290 from opentensor/sam-fix-merge-conflicts
sam0x17 Feb 14, 2025
eea733b
add CI action that requires clean merges between all named branches
sam0x17 Feb 14, 2025
74be0ea
fix
sam0x17 Feb 14, 2025
1ed6a9c
fixes
sam0x17 Feb 14, 2025
bd1556e
try again
sam0x17 Feb 14, 2025
1b6e89f
fix again
sam0x17 Feb 14, 2025
a4a3aaa
fix
sam0x17 Feb 14, 2025
8e061b7
fix
sam0x17 Feb 14, 2025
e0e8aab
merge with target branch
open-junius Feb 14, 2025
16cb2be
Merge pull request #1291 from opentensor/sam-clean-merges
sam0x17 Feb 14, 2025
efee1a0
stop needless wasting of CI hours with on push triggers we don't need
sam0x17 Feb 14, 2025
d98320d
Merge pull request #1293 from opentensor/sam-stop-push-actions
sam0x17 Feb 14, 2025
eb5188a
Merge pull request #1292 from opentensor/devnet-ready
sam0x17 Feb 14, 2025
5ca7820
Merge pull request #1294 from opentensor/devnet
sam0x17 Feb 14, 2025
894a518
provide an identity for github action to prevent failure
sam0x17 Feb 14, 2025
279e0e9
Merge pull request #1297 from opentensor/sam-fix-clean-merges-script
sam0x17 Feb 14, 2025
0485ab6
Add serve_axon extrinsic validation
gztensor Feb 14, 2025
1238e03
Bump spec version
gztensor Feb 14, 2025
f111118
Check IP validity in serve_axon validation first
gztensor Feb 14, 2025
a819d77
Merge pull request #1298 from opentensor/feat/validate-serve-axon
sam0x17 Feb 14, 2025
ecf7f52
Merge pull request #1131 from opentensor/feat/sudo_toggle_evm_precompile
sam0x17 Feb 14, 2025
de38a0b
Merge pull request #1299 from opentensor/devnet-ready
sam0x17 Feb 14, 2025
a8c6d4e
Merge pull request #1300 from opentensor/devnet
sam0x17 Feb 14, 2025
14a8758
make set diff only root
camfairchild Feb 15, 2025
4039b3b
add test for set diff no owner
camfairchild Feb 15, 2025
96e05ea
add migration for min diff
camfairchild Feb 15, 2025
e8d211a
bump spec
camfairchild Feb 15, 2025
cb03dd6
only allow top-stake SN owner hk to stay immune
camfairchild Feb 15, 2025
0784e5a
Merge pull request #1301 from opentensor/fix/set-diff-only-root
sam0x17 Feb 15, 2025
7ee8f74
add tests
camfairchild Feb 15, 2025
af41fa9
Merge branch 'devnet-ready' into hotfix/fix-sn-owner-unlimited-keys
camfairchild Feb 15, 2025
36e268b
Merge pull request #1302 from opentensor/hotfix/fix-sn-owner-unlimite…
sam0x17 Feb 15, 2025
a43217d
Merge pull request #1303 from opentensor/devnet-ready
sam0x17 Feb 15, 2025
3f581e1
only allow replace non-top-stake owner hk
camfairchild Feb 16, 2025
e375915
bump spec
camfairchild Feb 16, 2025
1019ad0
add tests using SubnetOwnerHotkey
camfairchild Feb 16, 2025
c6d3ae3
add impl for replace neuron
camfairchild Feb 16, 2025
ccb39d7
add swap test
camfairchild Feb 16, 2025
8f0a7cb
add neuron prune impl
camfairchild Feb 16, 2025
e9b0051
add swap hotkey impl
camfairchild Feb 16, 2025
40c53a2
clippy
camfairchild Feb 16, 2025
a89b2c2
clippy
camfairchild Feb 16, 2025
17ca77d
mistake in test
camfairchild Feb 16, 2025
fe40cb9
Merge pull request #1305 from opentensor/fix/allow-replace-sn-owner-h…
sam0x17 Feb 16, 2025
bb26e74
Merge pull request #1306 from opentensor/devnet-ready
sam0x17 Feb 16, 2025
c4d9601
Merge pull request #1304 from opentensor/devnet
sam0x17 Feb 16, 2025
b60e667
add some tests
camfairchild Feb 17, 2025
eca0849
add stake ext test
camfairchild Feb 17, 2025
73b2978
add move_stake tests
camfairchild Feb 17, 2025
67bf91f
cargo lock
camfairchild Feb 17, 2025
49f9e07
bump spec
camfairchild Feb 17, 2025
ed76f40
clpy
camfairchild Feb 17, 2025
392fce3
Merge branch 'main' into hotfix/fail-on-hk-pool-precision
camfairchild Feb 17, 2025
5a0236a
use bool return type
camfairchild Feb 17, 2025
82f8caf
clpy
camfairchild Feb 17, 2025
50837b2
add higher liquidity on mvoe stake tests
camfairchild Feb 17, 2025
dbbfb61
Merge pull request #1307 from opentensor/hotfix/fail-on-hk-pool-preci…
sam0x17 Feb 17, 2025
373f4c9
Merge pull request #1308 from opentensor/devnet-ready
sam0x17 Feb 17, 2025
f083c8b
Merge pull request #1309 from opentensor/devnet
sam0x17 Feb 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions pallets/subtensor/src/staking/stake_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,15 @@ impl<T: Config> Pallet<T> {
alpha_share_pool.update_value_for_one(coldkey, amount as i64);
}

pub fn try_increase_stake_for_hotkey_and_coldkey_on_subnet(
hotkey: &T::AccountId,
netuid: u16,
amount: u64,
) -> bool {
let mut alpha_share_pool = Self::get_alpha_share_pool(hotkey.clone(), netuid);
alpha_share_pool.sim_update_value_for_one(amount as i64)
}

/// Sell shares in the hotkey on a given subnet
///
/// The function updates share totals given current prices.
Expand Down Expand Up @@ -877,11 +886,18 @@ impl<T: Config> Pallet<T> {
Error::<T>::HotKeyAccountNotExists
);

let expected_alpha = Self::sim_swap_tao_for_alpha(netuid, stake_to_be_added);

// Ensure that we have adequate liquidity
ensure!(
Self::sim_swap_tao_for_alpha(netuid, stake_to_be_added).is_some(),
Error::<T>::InsufficientLiquidity
ensure!(expected_alpha.is_some(), Error::<T>::InsufficientLiquidity);

// Ensure hotkey pool is precise enough
let try_stake_result = Self::try_increase_stake_for_hotkey_and_coldkey_on_subnet(
hotkey,
netuid,
expected_alpha.unwrap_or(0),
);
ensure!(try_stake_result, Error::<T>::InsufficientLiquidity);

Ok(())
}
Expand Down Expand Up @@ -937,7 +953,7 @@ impl<T: Config> Pallet<T> {
origin_coldkey: &T::AccountId,
_destination_coldkey: &T::AccountId,
origin_hotkey: &T::AccountId,
_destination_hotkey: &T::AccountId,
destination_hotkey: &T::AccountId,
origin_netuid: u16,
destination_netuid: u16,
alpha_amount: u64,
Expand Down Expand Up @@ -975,7 +991,8 @@ impl<T: Config> Pallet<T> {
);

// Ensure that the stake amount to be removed is above the minimum in tao equivalent.
if let Some(tao_equivalent) = Self::sim_swap_alpha_for_tao(origin_netuid, alpha_amount) {
let tao_equivalent_result = Self::sim_swap_alpha_for_tao(origin_netuid, alpha_amount);
if let Some(tao_equivalent) = tao_equivalent_result {
ensure!(
tao_equivalent > DefaultMinStake::<T>::get(),
Error::<T>::AmountTooLow
Expand All @@ -992,6 +1009,18 @@ impl<T: Config> Pallet<T> {
}
}

let expected_alpha =
Self::sim_swap_tao_for_alpha(destination_netuid, tao_equivalent_result.unwrap_or(0))
.unwrap_or(0);

// Ensure that the amount being staked to the new hotkey is precise enough
let try_stake_result = Self::try_increase_stake_for_hotkey_and_coldkey_on_subnet(
destination_hotkey,
destination_netuid,
expected_alpha,
);
ensure!(try_stake_result, Error::<T>::InsufficientLiquidity);

if check_transfer_toggle {
// Ensure transfer is toggled.
ensure!(
Expand Down
275 changes: 274 additions & 1 deletion pallets/subtensor/src/tests/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use approx::assert_abs_diff_eq;
use frame_support::dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, Pays};
use frame_support::sp_runtime::DispatchError;
use sp_core::{Get, H256, U256};
use substrate_fixed::types::{I96F32, U96F32};
use substrate_fixed::types::{I96F32, U64F64, U96F32};

/***********************************************************
staking::add_stake() tests
Expand Down Expand Up @@ -3495,3 +3495,276 @@ fn test_remove_stake_limit_fill_or_kill() {
),);
});
}

// #[test]
// fn test_add_stake_specific() {
// new_test_ext(1).execute_with(|| {
// let sn_owner_coldkey = U256::from(55453);

// let hotkey_account_id = U256::from(533453);
// let coldkey_account_id = U256::from(55454);
// let hotkey_owner_account_id = U256::from(533454);

// let existing_shares: U64F64 =
// U64F64::from_num(161_986_254).saturating_div(U64F64::from_num(u64::MAX));
// let existing_stake = 36_711_495_953;
// let amount_added = 1_274_280_132;

// //add network
// let netuid: u16 = add_dynamic_network(&sn_owner_coldkey, &sn_owner_coldkey);

// // Register hotkey on netuid
// register_ok_neuron(netuid, hotkey_account_id, hotkey_owner_account_id, 0);
// // Check we have zero staked
// assert_eq!(
// SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id),
// 0
// );

// // Set a hotkey pool for the hotkey
// let mut hotkey_pool = SubtensorModule::get_alpha_share_pool(hotkey_account_id, netuid);
// hotkey_pool.update_value_for_one(&hotkey_owner_account_id, 1234); // Doesn't matter, will be overridden

// // Adjust the total hotkey stake and shares to match the existing values
// TotalHotkeyShares::<Test>::insert(hotkey_account_id, netuid, existing_shares);
// TotalHotkeyAlpha::<Test>::insert(hotkey_account_id, netuid, existing_stake);

// // Make the hotkey a delegate
// Delegates::<Test>::insert(hotkey_account_id, 0);

// // Add stake as new hotkey
// SubtensorModule::increase_stake_for_hotkey_and_coldkey_on_subnet(
// &hotkey_account_id,
// &coldkey_account_id,
// netuid,
// amount_added,
// );

// // Check the stake and shares are correct
// assert!(Alpha::<Test>::get((&hotkey_account_id, &coldkey_account_id, netuid)) > 0);
// assert_eq!(
// TotalHotkeyAlpha::<Test>::get(hotkey_account_id, netuid),
// amount_added + existing_stake
// );
// });
// }

// #[test]
// // RUST_LOG=info cargo test --package pallet-subtensor --lib -- tests::staking::test_add_stake_specific_stake_into_subnet --exact --show-output
// fn test_add_stake_specific_stake_into_subnet() {
// new_test_ext(1).execute_with(|| {
// let sn_owner_coldkey = U256::from(55453);

// let hotkey_account_id = U256::from(533453);
// let coldkey_account_id = U256::from(55454);
// let hotkey_owner_account_id = U256::from(533454);

// let existing_shares: U64F64 =
// U64F64::from_num(161_986_254).saturating_div(U64F64::from_num(u64::MAX));
// let existing_stake = 36_711_495_953;

// let tao_in = 2_409_892_148_947;
// let alpha_in = 15_358_708_513_716;

// let tao_staked = 200_000_000;
// let fee = DefaultStakingFee::<Test>::get();

// //add network
// let netuid: u16 = add_dynamic_network(&sn_owner_coldkey, &sn_owner_coldkey);

// // Register hotkey on netuid
// register_ok_neuron(netuid, hotkey_account_id, hotkey_owner_account_id, 0);
// // Check we have zero staked
// assert_eq!(
// SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id),
// 0
// );

// // Set a hotkey pool for the hotkey
// let mut hotkey_pool = SubtensorModule::get_alpha_share_pool(hotkey_account_id, netuid);
// hotkey_pool.update_value_for_one(&hotkey_owner_account_id, 1234); // Doesn't matter, will be overridden

// // Adjust the total hotkey stake and shares to match the existing values
// TotalHotkeyShares::<Test>::insert(hotkey_account_id, netuid, existing_shares);
// TotalHotkeyAlpha::<Test>::insert(hotkey_account_id, netuid, existing_stake);

// // Make the hotkey a delegate
// Delegates::<Test>::insert(hotkey_account_id, 0);

// // Setup Subnet pool
// SubnetAlphaIn::<Test>::insert(netuid, alpha_in);
// SubnetTAO::<Test>::insert(netuid, tao_in);

// // Add stake as new hotkey
// SubtensorModule::stake_into_subnet(
// &hotkey_account_id,
// &coldkey_account_id,
// netuid,
// tao_staked,
// fee,
// );

// // Check the stake and shares are correct
// assert!(Alpha::<Test>::get((&hotkey_account_id, &coldkey_account_id, netuid)) > 0);
// log::info!(
// "Alpha: {}",
// Alpha::<Test>::get((&hotkey_account_id, &coldkey_account_id, netuid))
// );
// log::info!(
// "TotalHotkeyAlpha: {}",
// TotalHotkeyAlpha::<Test>::get(hotkey_account_id, netuid)
// );
// });
// }

#[test]
// RUST_LOG=info cargo test --package pallet-subtensor --lib -- tests::staking::test_add_stake_specific_stake_into_subnet_fail --exact --show-output
fn test_add_stake_specific_stake_into_subnet_fail() {
new_test_ext(1).execute_with(|| {
let sn_owner_coldkey = U256::from(55453);

let hotkey_account_id = U256::from(533453);
let coldkey_account_id = U256::from(55454);
let hotkey_owner_account_id = U256::from(533454);

let existing_shares: U64F64 =
U64F64::from_num(161_986_254).saturating_div(U64F64::from_num(u64::MAX));
let existing_stake = 36_711_495_953;

let tao_in = 2_409_892_148_947;
let alpha_in = 15_358_708_513_716;

let tao_staked = 200_000_000;

//add network
let netuid: u16 = add_dynamic_network(&sn_owner_coldkey, &sn_owner_coldkey);

// Register hotkey on netuid
register_ok_neuron(netuid, hotkey_account_id, hotkey_owner_account_id, 0);
// Check we have zero staked
assert_eq!(
SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id),
0
);

// Set a hotkey pool for the hotkey
let mut hotkey_pool = SubtensorModule::get_alpha_share_pool(hotkey_account_id, netuid);
hotkey_pool.update_value_for_one(&hotkey_owner_account_id, 1234); // Doesn't matter, will be overridden

// Adjust the total hotkey stake and shares to match the existing values
TotalHotkeyShares::<Test>::insert(hotkey_account_id, netuid, existing_shares);
TotalHotkeyAlpha::<Test>::insert(hotkey_account_id, netuid, existing_stake);

// Make the hotkey a delegate
Delegates::<Test>::insert(hotkey_account_id, 0);

// Setup Subnet pool
SubnetAlphaIn::<Test>::insert(netuid, alpha_in);
SubnetTAO::<Test>::insert(netuid, tao_in);

// Give TAO balance to coldkey
SubtensorModule::add_balance_to_coldkey_account(
&coldkey_account_id,
tao_staked + 1_000_000_000,
);

// Add stake as new hotkey
assert_noop!(
SubtensorModule::add_stake(
RuntimeOrigin::signed(coldkey_account_id),
hotkey_account_id,
netuid,
tao_staked,
),
Error::<Test>::InsufficientLiquidity
);
});
}

#[test]
// RUST_LOG=info cargo test --package pallet-subtensor --lib -- tests::staking::test_move_stake_specific_stake_into_subnet_fail --exact --show-output
fn test_move_stake_specific_stake_into_subnet_fail() {
new_test_ext(1).execute_with(|| {
let sn_owner_coldkey = U256::from(55453);

let hotkey_account_id = U256::from(533453);
let coldkey_account_id = U256::from(55454);
let hotkey_owner_account_id = U256::from(533454);

let existing_shares: U64F64 =
U64F64::from_num(161_986_254).saturating_div(U64F64::from_num(u64::MAX));
let existing_stake = 36_711_495_953;

let tao_in = 2_409_892_148_947;
let alpha_in = 15_358_708_513_716;

let tao_staked = 200_000_000;

//add network
let netuid: u16 = add_dynamic_network(&sn_owner_coldkey, &sn_owner_coldkey);

let origin_netuid: u16 = add_dynamic_network(&sn_owner_coldkey, &sn_owner_coldkey);

// Register hotkey on netuid
register_ok_neuron(netuid, hotkey_account_id, hotkey_owner_account_id, 0);
// Register hotkey on origin netuid
register_ok_neuron(origin_netuid, hotkey_account_id, hotkey_owner_account_id, 0);

// Check we have zero staked
assert_eq!(
SubtensorModule::get_total_stake_for_hotkey(&hotkey_account_id),
0
);

// Set a hotkey pool for the hotkey on destination subnet
let mut hotkey_pool = SubtensorModule::get_alpha_share_pool(hotkey_account_id, netuid);
hotkey_pool.update_value_for_one(&hotkey_owner_account_id, 1234); // Doesn't matter, will be overridden

// Adjust the total hotkey stake and shares to match the existing values
TotalHotkeyShares::<Test>::insert(hotkey_account_id, netuid, existing_shares);
TotalHotkeyAlpha::<Test>::insert(hotkey_account_id, netuid, existing_stake);

// Make the hotkey a delegate
Delegates::<Test>::insert(hotkey_account_id, 0);

// Setup Subnet pool
SubnetAlphaIn::<Test>::insert(netuid, alpha_in);
SubnetTAO::<Test>::insert(netuid, tao_in);

// Give TAO balance to coldkey
SubtensorModule::add_balance_to_coldkey_account(
&coldkey_account_id,
tao_staked + 1_000_000_000,
);

// Setup Subnet pool for origin netuid
SubnetAlphaIn::<Test>::insert(origin_netuid, alpha_in + 10_000_000);
SubnetTAO::<Test>::insert(origin_netuid, tao_in + 10_000_000);

// Add stake as new hotkey
assert_ok!(SubtensorModule::add_stake(
RuntimeOrigin::signed(coldkey_account_id),
hotkey_account_id,
origin_netuid,
tao_staked,
),);
let alpha_to_move = SubtensorModule::get_stake_for_hotkey_and_coldkey_on_subnet(
&hotkey_account_id,
&coldkey_account_id,
origin_netuid,
);

// Move stake to destination subnet
assert_noop!(
SubtensorModule::move_stake(
RuntimeOrigin::signed(coldkey_account_id),
hotkey_account_id,
hotkey_account_id,
origin_netuid,
netuid,
alpha_to_move,
),
Error::<Test>::InsufficientLiquidity
);
});
}
23 changes: 23 additions & 0 deletions primitives/share-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ where
});
}

pub fn sim_update_value_for_one(&mut self, update: i64) -> bool {
let shared_value: U64F64 = self.state_ops.get_shared_value();
let denominator: U64F64 = self.state_ops.get_denominator();

// Then, update this key's share
if denominator == 0 {
true
} else {
// There are already keys in the pool, set or update this key
let value_per_share: I64F64 = I64F64::saturating_from_num(
shared_value
.checked_div(denominator) // denominator is never 0 here
.unwrap_or(U64F64::saturating_from_num(0)),
);

let shares_per_update: I64F64 = I64F64::saturating_from_num(update)
.checked_div(value_per_share)
.unwrap_or(I64F64::saturating_from_num(0));

shares_per_update != 0
}
}

/// Update the value associated with an item identified by the Key
pub fn update_value_for_one(&mut self, key: &K, update: i64) {
let shared_value: U64F64 = self.state_ops.get_shared_value();
Expand Down
Loading
Loading