feat: Add slippage protection options to stake swap and transfer comm…#758
feat: Add slippage protection options to stake swap and transfer comm…#758mimalsm wants to merge 5 commits intoopentensor:stagingfrom
Conversation
…ands This commit implements GitHub issue opentensor#644 by adding slippage protection options (--tolerance, --safe-staking, --allow-partial-stake) to both 'btcli stake swap' and 'btcli stake transfer' commands, making them consistent with 'btcli stake add'. Changes: - Added rate_tolerance, safe_staking, and allow_partial_stake parameters to stake_swap CLI command - Added rate_tolerance, safe_staking, and allow_partial_stake parameters to stake_transfer CLI command - Updated swap_stake() function in move.py to accept and use safe_swapping, allow_partial_stake, and rate_tolerance parameters - Modified swap_stake() to use swap_stake_limit when safe_swapping=True, which enforces price ratio limits on-chain to protect against slippage - Updated transfer_stake() function signature to accept these parameters for API consistency (chain-level support may be pending) - Integrated with existing ask_safe_staking(), ask_rate_tolerance(), and ask_partial_stake() helper methods for consistent user experience - Updated command docstrings with examples showing the new options Technical Details: - Safe swapping protects against price slippage by calculating: swap_rate_ratio = origin_price / destination_price limit_price = swap_rate_ratio * (1 + rate_tolerance) - Uses swap_stake_limit() instead of swap_stake() when safe_swapping=True - Default behavior matches stake_add: safe staking enabled, 5% tolerance - Options follow same naming conventions as stake_add: --tolerance/--rate-tolerance, --safe/--safe-staking, --unsafe/--no-safe-staking, --partial/--allow-partial-stake Fixes: opentensor#644
|
@thewhaleking can you please take a look? |
thewhaleking
left a comment
There was a problem hiding this comment.
Looks good on first viewing, but needs tests.
thanks for your review. did you mean I should add tests or manual tests on your end? |
|
@mimalsm Some e2e tests would be good for this. Ideally, the e2e test should test both, with and without slippage |
34bfe48 to
7b403a6
Compare
|
@ibraheem-abe @thewhaleking added a new test for slippage protection - it really takes long to run the tests (if you can give me a tip) |
ibraheem-abe
left a comment
There was a problem hiding this comment.
I don't understand why we added slippage_protection to transfer stake if it is a no-op under the hood?
|
I resolved all the issues you pointed, feel free to double check @ibraheem-abe |
|
I am closing this PR due to low effort and potentially putting the user's funds at risk. If this went through, users would be deceived into thinking they are using safe staking mechanism for We get it that you are mining gittensor, but PRs like this really puts the subnet in a negative light for the maintainers. Please ensure you understand how the codebase and the chain works before working on critical tasks like these. |

…ands
This commit implements GitHub issue #644 by adding slippage protection options (--tolerance, --safe-staking, --allow-partial-stake) to both 'btcli stake swap' and 'btcli stake transfer' commands, making them consistent with 'btcli stake add'.
Changes:
Technical Details:
Fixes: #644
Closes #644
Contribution by Gittensor, learn more at https://gittensor.io/