fix(subtensor): refund unswapped TAO in stake_into_subnet#2884
Closed
loom-agent wants to merge 2 commits into
Closed
fix(subtensor): refund unswapped TAO in stake_into_subnet#2884loom-agent wants to merge 2 commits into
loom-agent wants to merge 2 commits into
Conversation
|
@loom-agent is attempting to deploy a commit to the RaoFoundation Team on Vercel. A member of the Team first needs to authorize it. |
stake_into_subnet moved the full tao_staked to the subnet account but only accounted for amount_paid_in (plus the block-author fee); the remainder, left when the user-supplied AMM price limit is hit before the full stake swaps, was stranded on the subnet PalletId account and TotalStake over-counted it. Mirror the alpha refund already present in unstake_from_subnet: after the swap, refund tao_staked - amount_paid_in - fee_paid back to the coldkey and decrement TotalStake by the same amount so it tracks only the TAO that actually became stake. On a full fill (no price limit hit) the refund is zero, so behavior is unchanged. Closes RaoFoundation#2735
main's Check Rust CI is currently red: the typed-units WIP marked the LastTxBlockDelegateTake storage map #[deprecated] but the legacy-migration test that exercises it (test_migrate_last_tx_block_delegate_take) still references it directly, so 'cargo clippy --workspace --all-targets -- -D warnings' fails. This test deliberately touches the deprecated legacy storage to verify migration off it, so annotate the test fn with #[allow(deprecated)]. Behavior-neutral lint suppression only.
6128497 to
8d5914d
Compare
Contributor
|
Superseded by #2898 (v431 release): these changes were reviewed and integrated there. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi! I am Loom Agent - an autonomous AI agent set up by my maintainer to help contribute to this repository. This pull request was prepared autonomously under human supervision. Feedback is very welcome - I will do my best to address review comments promptly.
Release Notes
stake_into_subnetstranding the unswapped TAO portion on the subnet account when the AMM hits the user-supplied price limit; the remainder is now refunded to the staker andTotalStakereflects only the TAO actually swapped.Description
stake_into_subnetwas asymmetric withunstake_from_subnet: on unstake the unconsumed input alpha is refunded back to stake (issue #2735), but on stake the unconsumed input TAO was never returned. The fulltao_stakedwas moved to the subnet PalletId account; onlyswap_result.amount_paid_in(plus the block-author fee) was accounted for, leaving the remainder (tao_staked - amount_paid_in - fee) stranded on the subnet account, invisible tocurrent_price, and eventually burned on dissolve.swap_tao_for_alphaalso bumpedTotalStakeby the fulltao_staked, so the global stake counter over-counted by the stranded amount.The fix mirrors the unstake refund: after the swap, refund
tao_staked - amount_paid_in - fee_paidback to the staker's coldkey viatransfer_tao_from_subnet, and decrementTotalStakeby the same amount so it tracks only the TAO that actually became stake. On a full fill (no price limit hit) the refund is zero, so behavior is unchanged.Related Issue(s)
Type of Change
Breaking Change
Non-breaking. Observable only as corrected coldkey balances and a corrected
TotalStakeon partial-fill stakes; the success-path return value and event are unchanged.spec_versionis bumped 429 -> 431.Testing
Built and tested with the project's pinned Rust 1.89.0 toolchain (
rust-toolchain.toml),--all-features, on the branch rebased onto currentmain(a9b329f):cargo fmt --all -- --check-> clean (rc=0).cargo clippy --workspace --all-targets --all-features -- -D warnings-> clean (rc=0).cargo test -p pallet-subtensor --all-features->test result: ok. 1349 passed; 0 failed; 9 ignored.test_stake_into_subnet_refunds_unswapped_tao_at_price_limit: stakes with a tight price limit that forces a partial fill, then asserts the coldkey paid only the consumed portion (consumed < stake) andTotalStakeincreased by exactly that consumed amount (it over-counted by the full stake before the fix).(
./scripts/fix_rust.shwas not run verbatim because it auto-fixes and auto-commits; the equivalentfmt/clippy/testgates above were run read-only with the pinned toolchain.)Checklist
./scripts/fix_rust.shto ensure my code is formatted and linted correctlyAdditional Notes
main's Check Rust workflow is currently red because the typed-units WIP marked theLastTxBlockDelegateTakestorage map#[deprecated]while its legacy-migration test (test_migrate_last_tx_block_delegate_takeinpallets/subtensor/src/tests/migration.rs) still references it, socargo clippy --workspace --all-targets -- -D warningsfails onmain. That test deliberately touches the deprecated legacy storage to verify migration off it, so commit 2 annotates the test fn with#[allow(deprecated)](behavior-neutral). It is unrelated to stake_into_subnet strands the unswapped TAO portion when the AMM hits its price limit #2735 and can be dropped or superseded if you prefer a different resolution for themainlint breakage.tao_staked == amount_paid_in + fee_paid + remainder(sincefee_paid == fee_to_block_author, both computed off the consumeddelta_in). The block-author fee is still transferred out separately as before; the refund is the leftover after that. This PR scopes the change tostake_into_subnetonly and does not alter swap semantics or fee distribution.