Skip to content
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

TriggerOrder close order logic changes #514

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

EdNoepel
Copy link
Contributor

@EdNoepel EdNoepel commented Dec 17, 2024

There is a use case where users submit a trigger order to close their position alongside an intent for opening a position. When this happens, the trigger order becomes immediately executable. When the trigger order executes as a no-op update, the UX is that their trigger order disappeared.

To work around this behavior, update logic such that trigger orders to close are not executable if user has no position.

This PR is a follow-up to #513. Differences:

  • This moves logic out of TriggerOrder type and into Manager, as requested in the other PR.
  • This also checks pending positions.

Note that I do not necessarily agree with the first change. Passing market and account into the the method seems better for maintainability. I recommend we take that approach when merging into v2.4 branch, unless we wish to abandon this behavior and implement a trigger order dependency on intent execution feature instead.

TODO

  • Self-review
  • Merge this to v2.4 branch after approval

position.update(pending);
} else {
position = Position(0, UFixed6Lib.ZERO, UFixed6Lib.ZERO, UFixed6Lib.ZERO);
}
Copy link
Contributor Author

@EdNoepel EdNoepel Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels awkward, but avoids encumbering every order execution with three additional storage slot reads.

Copy link

[Periphery] Unit Test Coverage Report

Coverage after merging ed/dont-close-without-position-2 into main will be
66.85%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/perennial-account/contracts
   Account.sol27.78%100%22.22%29.63%103, 108–109, 58, 64, 67–68, 71, 76–78, 81, 83–84, 89, 94–97
   AccountVerifier.sol100%100%100%100%
   Controller.sol81%100%100%75.95%103–105, 112–113, 204, 216, 227, 229–231, 235–237, 240, 250–252, 259
   Controller_Arbitrum.sol0%100%0%0%29, 41
   Controller_Incentivized.sol0%100%0%0%111, 128–129, 146, 154, 156–157, 164, 183, 186, 205, 208, 227, 230, 249, 252, 271, 274, 286–287, 290, 293, 302–303, 305, 307, 309, 56, 72–77, 94
packages/perennial-account/contracts/libs
   RebalanceLib.sol0%100%0%0%26, 29–30, 32–33, 36, 39, 43
packages/perennial-account/contracts/test
   RebalanceConfigTester.sol100%100%100%100%
packages/perennial-account/contracts/types
   Action.sol100%100%100%100%
   DeployAccount.sol100%100%100%100%
   MarketTransfer.sol100%100%100%100%
   RebalanceConfig.sol100%100%100%100%
   RebalanceConfigChange.sol100%100%100%100%
   RelayedAccessUpdateBatch.sol100%100%100%100%
   RelayedGroupCancellation.sol100%100%100%100%
   RelayedNonceCancellation.sol100%100%100%100%
   RelayedOperatorUpdate.sol100%100%100%100%
   RelayedSignerUpdate.sol100%100%100%100%
   Withdrawal.sol100%100%100%100%
packages/perennial-extensions/contracts
   Coordinator.sol100%100%100%100%
   MultiInvoker.sol90%100%92.86%89.34%101–102, 182, 184, 204, 207, 275, 379, 394, 412, 414, 416, 418
   MultiInvoker_Arbitrum.sol0%100%0%0%43, 51
   MultiInvoker_Optimism.sol0%100%0%0%43, 51
packages/perennial-extensions/contracts/types
   TriggerOrder.sol96.43%100%100%95.83%54
packages/perennial-oracle/contracts
   Oracle.sol100%100%100%100%
   OracleFactory.sol93.55%100%88.89%95.45%65
packages/perennial-oracle/contracts/chainlink
   ChainlinkFactory.sol100%100%100%100%
packages/perennial-oracle/contracts/keeper
   KeeperFactory.sol87.36%100%78.57%89.04%173–174, 176–177, 221, 248, 91–92
   KeeperOracle.sol71.79%100%70.59%72.13%110, 155, 165, 167–169, 171, 173–177, 180–181, 226, 73, 87
   KeeperOracle_Migration.sol0%100%0%0%26–27
packages/perennial-oracle/contracts/keeper/libs
   DedupLib.sol100%100%100%100%
packages/perennial-oracle/contracts/keeper/types
   KeeperOracleParameter.sol100%100%100%100%
   PriceResponse.sol100%100%100%100%
packages/perennial-oracle/contracts/metaquants
   MetaQuantsFactory.sol0%100%0%0%25–27, 33–36, 40, 51–52, 54–57, 59, 61, 63, 65–66, 75
packages/perennial-oracle/contracts/payoff
   Inverse.sol100%100%100%100%
   PowerHalf.sol100%100%100%100%
   PowerTwo.sol100%100%100%100%
packages/perennial-oracle/contracts/pyth
   PythFactory.sol100%100%100%100%
packages/perennial-oracle/contracts/types
   OracleParameter.sol100%100%100%100%
packages/perennial-order/contracts
   Manager.sol79.55%100%83.33%78.57%137–139, 177–178, 180, 218, 222, 224, 226, 247–249, 264–265
   Manager_Arbitrum.sol100%100%100%100%
   OrderVerifier.sol100%100%100%100%
packages/perennial-order/contracts/test
   TriggerOrderTester.sol100%100%100%100%
packages/perennial-order/contracts/types
   Action.sol100%100%100%100%
   CancelOrderAction.sol100%100%100%100%
   InterfaceFee.sol100%100%100%100%
   PlaceOrderAction.sol100%100%100%100%
   TriggerOrder.sol100%100%100%100%
packages/perennial-vault/contracts
   Vault.sol0%100%0%0%100, 106, 112–113, 121–122, 131, 133, 140, 142, 148, 150–151, 154, 160–161, 163, 165–166, 173–175, 183–187, 194, 196, 198, 204, 206, 208–211, 214, 220–221, 227–228, 234–235, 237–238, 245–246, 248–250, 264–265, 267–270, 276–277, 279–281, 299–300, 303–313, 316, 319–321, 324–326, 328, 335, 345–346, 353, 356, 360–361, 367–368, 371, 374, 378, 391, 393, 401–406, 416, 422, 439, 453, 455–458, 460, 462–463, 466–468, 472–474, 477–479, 486–488, 495, 508–509, 512, 68, 70–73, 79, 86, 93
   VaultFactory.sol0%100%0%0%33–34, 39, 53, 57–59, 61, 68–69
packages/perennial-vault/contracts/libs
   StrategyLib.sol0%100%0%0%116–117, 119–120, 122–126, 132, 135–136, 150, 153, 157, 159, 162, 164, 176–180, 182–183, 185–186, 188, 194, 196, 199–202, 205, 90–95
packages/perennial-vault/contracts/types
   Account.sol100%100%100%100%
   Checkpoint.sol100%100%100%100%
   Registration.sol100%100%100%100%
   VaultParameter.sol100%100%100%100%
packages/perennial-verifier/contracts
   Verifier.sol100%100%100%100%
packages/perennial-verifier/contracts/types
   AccessUpdate.sol100%100%100%100%
   AccessUpdateBatch.sol100%100%100%100%
   Intent.sol100%100%100%100%
   OperatorUpdate.sol100%100%100%100%
   SignerUpdate.sol100%100%100%100%

@EdNoepel EdNoepel marked this pull request as ready for review December 17, 2024 13:53
Copy link

[Core] Integration Test Coverage Report

Coverage after merging ed/dont-close-without-position-2 into main will be
96.67%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/perennial/contracts
   Market.sol97.21%92%97.78%99.53%130, 130–131, 136, 150, 191, 243, 714, 886
   MarketFactory.sol96.74%90.63%100%100%125, 151, 180
packages/perennial/contracts/interfaces
   IMarket.sol100%100%100%100%
   IMarketFactory.sol100%100%100%100%
   IOracleProvider.sol100%100%100%100%
   IOracleProviderFactory.sol100%100%100%100%
packages/perennial/contracts/libs
   CheckpointLib.sol100%100%100%100%
   InvariantLib.sol60.66%47.50%100%85%109, 115–116, 35–36, 38–39, 39, 39, 39, 48, 52, 52, 60, 65–66, 66, 72–73, 77, 83–84, 84, 98
   MagicValueLib.sol63.16%50%100%62.50%55–58, 58, 58–59
   VersionLib.sol98.76%95.83%100%99.18%442–443
packages/perennial/contracts/types
   Checkpoint.sol74.07%50%100%100%50–56
   Global.sol79.69%53.57%100%100%145–157
   Guarantee.sol89.55%65%100%100%197–199, 222–225
   Local.sol82.14%50%100%100%84–88
   MarketParameter.sol76.67%50%100%87.50%100–101, 85–86, 88–89, 99
   OracleReceipt.sol100%100%100%100%
   OracleVersion.sol100%100%100%100%
   Order.sol85.12%63.79%96.77%96.20%103, 103, 109–110, 162, 182, 182, 240, 396–401, 472–474, 500–505, 99
   Position.sol77.19%57.69%87.10%80.70%111, 148, 203, 216, 300, 334–336, 350–352, 355, 355, 355, 355, 355–356, 358–360, 419, 441
   ProtocolParameter.sol73.53%50%100%100%71–73, 79–84
   RiskParameter.sol69.33%47.62%100%96.67%134, 140, 142, 148, 150–151, 153–154, 156, 158, 160, 168, 168, 168–169, 179–186
   Version.sol70.27%50%100%100%100–119, 98–99

Copy link

[Periphery] Integration Test Coverage Report

Coverage after merging ed/dont-close-without-position-2 into main will be
93.49%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/perennial-account/contracts
   Account.sol100%100%100%100%
   AccountVerifier.sol91.67%100%91.67%91.67%38
   Controller.sol92%100%90.48%92.41%147, 155, 271, 274, 289, 306
   Controller_Arbitrum.sol100%100%100%100%
   Controller_Incentivized.sol100%100%100%100%
packages/perennial-account/contracts/libs
   RebalanceLib.sol100%100%100%100%
packages/perennial-account/contracts/test
   RebalanceConfigTester.sol0%100%0%0%10, 14
packages/perennial-account/contracts/types
   Action.sol100%100%100%100%
   DeployAccount.sol100%100%100%100%
   MarketTransfer.sol100%100%100%100%
   RebalanceConfig.sol20%100%33.33%14.29%34–35, 43–44, 46, 50
   RebalanceConfigChange.sol85.71%100%100%83.33%43
   RelayedAccessUpdateBatch.sol100%100%100%100%
   RelayedGroupCancellation.sol100%100%100%100%
   RelayedNonceCancellation.sol100%100%100%100%
   RelayedOperatorUpdate.sol100%100%100%100%
   RelayedSignerUpdate.sol100%100%100%100%
   Withdrawal.sol100%100%100%100%
packages/perennial-extensions/contracts
   Coordinator.sol0%100%0%0%20, 26–27, 33–34, 40–42, 49–50
   MultiInvoker.sol100%100%100%100%
   MultiInvoker_Arbitrum.sol0%100%0%0%43, 51
   MultiInvoker_Optimism.sol0%100%0%0%43, 51
packages/perennial-extensions/contracts/types
   TriggerOrder.sol96.43%100%100%95.83%54
packages/perennial-oracle/contracts
   Oracle.sol65.33%100%65%65.45%101, 106, 118–119, 128, 155, 178–179, 181, 183–184, 195, 197, 202–203, 54, 67–68, 75
   OracleFactory.sol93.55%100%88.89%95.45%73
packages/perennial-oracle/contracts/chainlink
   ChainlinkFactory.sol100%100%100%100%
packages/perennial-oracle/contracts/keeper
   KeeperFactory.sol95.40%100%85.71%97.26%221, 85
   KeeperOracle.sol96.15%100%94.12%96.72%155, 87
   KeeperOracle_Migration.sol0%100%0%0%26–27
packages/perennial-oracle/contracts/keeper/libs
   DedupLib.sol100%100%100%100%
packages/perennial-oracle/contracts/keeper/types
   KeeperOracleParameter.sol93.75%100%100%92.31%56
   PriceResponse.sol91.30%100%100%87.50%78–79
packages/perennial-oracle/contracts/metaquants
   MetaQuantsFactory.sol100%100%100%100%
packages/perennial-oracle/contracts/payoff
   Inverse.sol0%100%0%0%9
   PowerHalf.sol0%100%0%0%13
   PowerTwo.sol100%100%100%100%
packages/perennial-oracle/contracts/pyth
   PythFactory.sol100%100%100%100%
packages/perennial-oracle/contracts/types
   OracleParameter.sol100%100%100%100%
packages/perennial-order/contracts
   Manager.sol100%100%100%100%
   Manager_Arbitrum.sol100%100%100%100%
   OrderVerifier.sol100%100%100%100%
packages/perennial-order/contracts/test
   TriggerOrderTester.sol0%100%0%0%17, 21, 25, 29
packages/perennial-order/contracts/types
   Action.sol100%100%100%100%
   CancelOrderAction.sol100%100%100%100%
   InterfaceFee.sol100%100%100%100%
   PlaceOrderAction.sol100%100%100%100%
   TriggerOrder.sol95.65%100%100%94.44%125, 52
packages/perennial-vault/contracts
   Vault.sol100%100%100%100%
   VaultFactory.sol100%100%100%100%
packages/perennial-vault/contracts/libs
   StrategyLib.sol100%100%100%100%
packages/perennial-vault/contracts/types
   Account.sol100%100%100%100%
   Checkpoint.sol100%100%100%100%
   Registration.sol100%100%100%100%
   VaultParameter.sol100%100%100%100%

Copy link

[Periphery] Combined Test Coverage Report

Coverage after merging ed/dont-close-without-position-2 into main will be
99.06%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/perennial-account/contracts
   Account.sol100%100%100%100%
   AccountVerifier.sol100%100%100%100%
   Controller.sol100%100%100%100%
   Controller_Arbitrum.sol100%100%100%100%
   Controller_Incentivized.sol100%100%100%100%
packages/perennial-account/contracts/libs
   RebalanceLib.sol100%100%100%100%
packages/perennial-account/contracts/test
   RebalanceConfigTester.sol100%100%100%100%
packages/perennial-account/contracts/types
   Action.sol100%100%100%100%
   DeployAccount.sol100%100%100%100%
   MarketTransfer.sol100%100%100%100%
   RebalanceConfig.sol100%100%100%100%
   RebalanceConfigChange.sol100%100%100%100%
   RelayedAccessUpdateBatch.sol100%100%100%100%
   RelayedGroupCancellation.sol100%100%100%100%
   RelayedNonceCancellation.sol100%100%100%100%
   RelayedOperatorUpdate.sol100%100%100%100%
   RelayedSignerUpdate.sol100%100%100%100%
   Withdrawal.sol100%100%100%100%
packages/perennial-extensions/contracts
   Coordinator.sol100%100%100%100%
   MultiInvoker.sol100%100%100%100%
   MultiInvoker_Arbitrum.sol0%100%0%0%43, 51
   MultiInvoker_Optimism.sol0%100%0%0%43, 51
packages/perennial-extensions/contracts/types
   TriggerOrder.sol96.43%100%100%95.83%54
packages/perennial-oracle/contracts
   Oracle.sol100%100%100%100%
   OracleFactory.sol100%100%100%100%
packages/perennial-oracle/contracts/chainlink
   ChainlinkFactory.sol100%100%100%100%
packages/perennial-oracle/contracts/keeper
   KeeperFactory.sol97.70%100%92.86%98.63%221
   KeeperOracle.sol96.15%100%94.12%96.72%155, 87
   KeeperOracle_Migration.sol0%100%0%0%26–27
packages/perennial-oracle/contracts/keeper/libs
   DedupLib.sol100%100%100%100%
packages/perennial-oracle/contracts/keeper/types
   KeeperOracleParameter.sol100%100%100%100%
   PriceResponse.sol100%100%100%100%
packages/perennial-oracle/contracts/metaquants
   MetaQuantsFactory.sol100%100%100%100%
packages/perennial-oracle/contracts/payoff
   Inverse.sol100%100%100%100%
   PowerHalf.sol100%100%100%100%
   PowerTwo.sol100%100%100%100%
packages/perennial-oracle/contracts/pyth
   PythFactory.sol100%100%100%100%
packages/perennial-oracle/contracts/types
   OracleParameter.sol100%100%100%100%
packages/perennial-order/contracts
   Manager.sol100%100%100%100%
   Manager_Arbitrum.sol100%100%100%100%
   OrderVerifier.sol100%100%100%100%
packages/perennial-order/contracts/test
   TriggerOrderTester.sol100%100%100%100%
packages/perennial-order/contracts/types
   Action.sol100%100%100%100%
   CancelOrderAction.sol100%100%100%100%
   InterfaceFee.sol100%100%100%100%
   PlaceOrderAction.sol100%100%100%100%
   TriggerOrder.sol100%100%100%100%
packages/perennial-vault/contracts
   Vault.sol100%100%100%100%
   VaultFactory.sol100%100%100%100%
packages/perennial-vault/contracts/libs
   StrategyLib.sol100%100%100%100%
packages/perennial-vault/contracts/types
   Account.sol100%100%100%100%
   Checkpoint.sol100%100%100%100%
   Registration.sol100%100%100%100%
   VaultParameter.sol100%100%100%100%
packages/perennial-verifier/contracts
   Verifier.sol100%100%100%100%
packages/perennial-verifier/contracts/types
   AccessUpdate.sol100%100%100%100%
   AccessUpdateBatch.sol100%100%100%100%
   Intent.sol100%100%100%100%
   OperatorUpdate.sol100%100%100%100%
   SignerUpdate.sol100%100%100%100%

Copy link

[Core] Unit Test Coverage Report

Coverage after merging ed/dont-close-without-position-2 into main will be
98.80%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/perennial/contracts
   Market.sol98.88%98%97.78%99.53%130–131, 150
   MarketFactory.sol100%100%100%100%
packages/perennial/contracts/interfaces
   IMarket.sol100%100%100%100%
   IMarketFactory.sol100%100%100%100%
   IOracleProvider.sol100%100%100%100%
   IOracleProviderFactory.sol100%100%100%100%
packages/perennial/contracts/libs
   CheckpointLib.sol100%100%100%100%
   InvariantLib.sol100%100%100%100%
   MagicValueLib.sol100%100%100%100%
   VersionLib.sol100%100%100%100%
packages/perennial/contracts/types
   Checkpoint.sol100%100%100%100%
   Global.sol96.88%92.86%100%100%151, 153
   Guarantee.sol100%100%100%100%
   Local.sol100%100%100%100%
   MarketParameter.sol100%100%100%100%
   OracleReceipt.sol100%100%100%100%
   OracleVersion.sol100%100%100%100%
   Order.sol98.21%94.83%100%100%103, 399, 99
   Position.sol88.60%84.62%96.77%85.96%350–352, 355, 355, 355, 355, 355–356, 358–360
   ProtocolParameter.sol100%100%100%100%
   RiskParameter.sol96%92.86%100%100%179, 182, 186
   Version.sol100%100%100%100%

Copy link

[Core] Combined Test Coverage Report

Coverage after merging ed/dont-close-without-position-2 into main will be
98.80%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/perennial/contracts
   Market.sol99.22%100%97.62%99.53%131
   MarketFactory.sol100%100%100%100%
packages/perennial/contracts/libs
   CheckpointLib.sol100%100%100%100%
   InvariantLib.sol100%100%100%100%
   MagicValueLib.sol100%100%100%100%
   VersionLib.sol100%100%100%100%
packages/perennial/contracts/types
   Checkpoint.sol100%100%100%100%
   Global.sol100%100%100%100%
   Guarantee.sol100%100%100%100%
   Local.sol100%100%100%100%
   MarketParameter.sol100%100%100%100%
   Order.sol100%100%100%100%
   Position.sol89.02%100%96%85.96%350–352, 355–356, 358–360
   ProtocolParameter.sol100%100%100%100%
   RiskParameter.sol100%100%100%100%
   Version.sol100%100%100%100%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant