- 
                Notifications
    
You must be signed in to change notification settings  - Fork 54
 
1223 autoclose feature #1332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
1223 autoclose feature #1332
Conversation
Added navigation + ui
Replaces the autoclose logic with a more flexible modify operation for perpetual positions, supporting take profit, stop loss, and cancel actions. Updates related models, view models, navigation, formatters, and transaction filtering to use the new PerpetualModifyType and PerpetualModifyConfirmData structures. Adds mapping extensions and updates HyperCoreSigner to handle new modify and cancel order flows.
Renamed and reorganized action handlers for confirming and canceling take profit in AutocloseScene and its ViewModel. Button actions now call more clearly named methods, and logic for setting and canceling take profit is moved to private methods for better encapsulation. Button type logic updated to disable confirmation when appropriate.
Updated variable names from markPrice to marketPrice in AutocloseScene and its ViewModel for clarity and consistency. Modified NativeProvider to return AlienResponse instead of Data, adding response status and cache handling.
Added a test case to ensure that the .perpetualModify transaction type is correctly mapped to the .perpetuals filter type.
Added percent selection accessory to AutocloseScene and improved input field focus management. Updated profit calculation logic in AutocloseSceneViewModel to use initial margin, and exposed percent-based price selection. Refactored PerpetualPriceFormatter to allow configurable decimal precision for input formatting. Minor improvements to autoclose text display in PerpetualPositionViewModel.
Moved profit calculation logic to a private computed property for reuse and clarity. Updated expected profit percent, text, and color to use the new property. Also changed PercentageAccessoryView's onDone handler to use model.onDone for better encapsulation.
Removed separate tp and sl cases from PerpetualModifyType, consolidating them into a single tpsl case with optional takeProfit and stopLoss fields. Updated related mapping, usage, and logic in AutocloseSceneViewModel, TransferDataType, and HyperCoreSigner to reflect this change for improved code clarity and maintainability.
Updated code to use the TPSLOrderData struct instead of passing individual parameters for TPSL order types. Adjusted mapping functions and related usages in AutocloseSceneViewModel and TransferDataType to accommodate this change, improving type safety and code clarity.
Refactored the usage of the .cancel and .tpsl cases in PerpetualModifyConfirmData and HyperCoreSigner to use updated parameter structures. Updated the core submodule to the latest commit.
Updated ConfirmDetailsViewModel to handle PerpetualType cases explicitly, returning an empty view model for the .modify case. Refactored PerpetualType+Primitives extension to remove the data property and ensure baseAsset is accessed correctly for all cases.
Changed PerpetualModifyConfirmData to use an array of modifyTypes instead of a single modifyType across primitives, extensions, and usage sites. Updated related logic in TransferDataType and HyperCoreSigner to handle multiple modify types, enabling batch modifications and improved flexibility.
Standardized 'Auto close' to 'Auto Close' in InfoSheet and PerpetualPositionViewModel. Improved autocloseText logic to display both Take Profit and Stop Loss prices when available, or show '-' if neither is set.
Reworked the autoclose scene to support both take profit and stop loss, introducing AutocloseType, AutocloseEstimator, AutocloseField, and AutocloseModifyBuilder. Updated validation logic, input sections, and view model to handle both types, and refactored error handling and validators for general autoclose functionality.
Advanced the core submodule pointer to commit abef2a494df5d3a19b1614daa8024cea62686eb0. This brings in the latest changes from the core repository.
Changed the base asset from Asset.hyperliquidUSDC() to .hypercoreUSDC() in AutocloseSceneViewModel. Also updated the core submodule to the latest commit.
Removed AutocloseType and introduced TpslType enum with raw values for take profit and stop loss. Updated all references and usages in Perpetuals features and Validators to use TpslType, improving type clarity and serialization. Updated local settings and core submodule pointer.
Replaced hardcoded Auto Close strings in Perpetuals feature with localized values. Added new localization keys and translations for Auto Close, including description, trigger price, take profit, stop loss, market price, and estimated PNL in all supported languages.
Replaced hasChanges with canBuild in AutocloseModifyBuilder to ensure take profit and stop loss fields are valid before allowing modifications. Updated usage in AutocloseSceneViewModel to use the new validation logic.
Introduces new localized string keys and accessors for 'increase direction' and 'reduce direction' in all supported languages. Also updates the fallback for 'Estimated Pnl' to use consistent casing.
Introduces AutocloseFormatter to standardize TP/SL display and adds PerpetualModifyViewModel for perpetual modify confirmation. Updates PerpetualModifyConfirmData to include takeProfitOrderId and stopLossOrderId, propagates these changes through related view models and extension mappings, and ensures proper rendering in ConfirmTransferScene.
Enhanced autoclose validation and error messaging to account for position direction (long/short). The validator now checks trigger price validity based on both type and direction, and error descriptions reflect the correct comparison. Updated related view model and estimator logic to support these changes.
| case smartContractCall | ||
| case perpetualOpenPosition | ||
| case perpetualClosePosition | ||
| case perpetualModify | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot
| case perpetualModify | |
| case perpetualModify | 
| case perpetualModify | |
| case perpetualModifyPosition | 
| 
           @gemcoder21 I've opened a new pull request, #1355, to work on those changes. Once the pull request is ready, I'll request review from you.  | 
    
| } | ||
| } | ||
| 
               | 
          ||
| public enum PerpetualModifyType: Codable, Equatable, Hashable, Sendable { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public enum PerpetualModifyType: Codable, Equatable, Hashable, Sendable { | |
| public enum PerpetualModifyPositionType: Codable, Equatable, Hashable, Sendable { | 
| Localized.Stake.validator | ||
| case .stakeFreeze, .stakeUnfreeze: | ||
| Localized.Stake.resource | ||
| case .swap, .stakeUndelegate, .stakeRedelegate, .stakeRewards, | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| case .swap, .stakeUndelegate, .stakeRedelegate, .stakeRewards, | |
| case .swap, .stakeUndelegate, .stakeRedelegate, .stakeRewards, perpetualModify | 
| @Binding var inputModel: InputValidationViewModel | ||
| let title: String | ||
| let placeholder: String | ||
| let estimatedPNLTitle: String | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| let estimatedPNLTitle: String | |
| let pnlTitle: String | 
no need to use estimated
| } | ||
| 
               | 
          ||
| func onSelectPercent(_ percent: Int) { | ||
| let type: TpslType = focusField == .takeProfit ? .takeProfit : .stopLoss | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use switch here
| func onSelectPercent(_ percent: Int) { | ||
| let type: TpslType = focusField == .takeProfit ? .takeProfit : .stopLoss | ||
| let targetPrice = estimator.calculateTargetPriceFromROE(roePercent: percent, type: type) | ||
| let inputModel = type == .takeProfit ? takeProfitInput : stopLossInput | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
* Initial plan * Rename perpetualModify to perpetualModifyPosition Co-authored-by: gemcoder21 <104884878+gemcoder21@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: gemcoder21 <104884878+gemcoder21@users.noreply.github.com>
closes #1223