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

[Fix] Add margin #92

Merged
merged 8 commits into from
Sep 5, 2023
Merged

[Fix] Add margin #92

merged 8 commits into from
Sep 5, 2023

Conversation

kbrizzle
Copy link
Collaborator

@kbrizzle kbrizzle commented Sep 1, 2023

Core

  • Adds margin / minMargin risk parameters that apply to the current pending position, while moving maintenance / minMaintenance to only apply to the non-current pending and latest positions.

Vault

  • Switches to margin instead of maintenance for all minimum collateral checks (since positions are frequently updated, margin is a more accurate lower bound)
  • Adds a buffer to minMargin corresponding to the buffer between leverage and maintenance, whereas before it would use minMargin directly leading to situations where it could be near a liquidation.

Fixes: sherlock-audit/2023-07-perennial-judging#104.

(applicable to many reported issues)

@kbrizzle kbrizzle changed the title [WIP] Add margin [Fix] Add margin Sep 3, 2023
@kbrizzle kbrizzle force-pushed the britz-add-margin branch 2 times, most recently from a38072b to 312b5e3 Compare September 4, 2023 21:22
@kbrizzle kbrizzle changed the base branch from main to britz-fix-failing-ci September 4, 2023 23:24
@github-actions
Copy link

github-actions bot commented Sep 4, 2023

[Payoff] Unit Test Code Coverage Report

Coverage after merging britz-add-margin into main will be
100.00%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/perennial-payoff/contracts
   PayoffFactory.sol100%100%100%100%
packages/perennial-payoff/contracts/interfaces
   IPayoffFactory.sol100%100%100%100%
packages/perennial-payoff/contracts/payoff
   Giga.sol100%100%100%100%
   Kilo.sol100%100%100%100%
   KiloPowerHalf.sol100%100%100%100%
   KiloPowerTwo.sol100%100%100%100%
   Mega.sol100%100%100%100%
   MegaPowerTwo.sol100%100%100%100%
   Micro.sol100%100%100%100%
   MicroPowerTwo.sol100%100%100%100%
   Milli.sol100%100%100%100%
   MilliPowerHalf.sol100%100%100%100%
   MilliPowerTwo.sol100%100%100%100%
   Nano.sol100%100%100%100%
   PowerHalf.sol100%100%100%100%
   PowerTwo.sol100%100%100%100%

@github-actions
Copy link

github-actions bot commented Sep 4, 2023

[Payoff] Integration Test Code Coverage Report

Coverage after merging britz-add-margin into main will be
100.00%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/perennial-payoff/contracts
   PayoffFactory.sol100%100%100%100%
packages/perennial-payoff/contracts/interfaces
   IPayoffFactory.sol100%100%100%100%
packages/perennial-payoff/contracts/payoff
   Giga.sol100%100%100%100%
   Kilo.sol100%100%100%100%
   KiloPowerHalf.sol100%100%100%100%
   KiloPowerTwo.sol100%100%100%100%
   Mega.sol100%100%100%100%
   MegaPowerTwo.sol100%100%100%100%
   Micro.sol100%100%100%100%
   MicroPowerTwo.sol100%100%100%100%
   Milli.sol100%100%100%100%
   MilliPowerHalf.sol100%100%100%100%
   MilliPowerTwo.sol100%100%100%100%
   Nano.sol100%100%100%100%
   PowerHalf.sol100%100%100%100%
   PowerTwo.sol100%100%100%100%

@github-actions
Copy link

github-actions bot commented Sep 4, 2023

[Extensions] Unit Test Coverage Report

Coverage after merging britz-add-margin into main will be
83.46%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/perennial-extensions/contracts
   MultiInvoker.sol79.09%73.17%86.96%81.74%104, 143–144, 147–149, 151, 156, 225, 225–226, 228, 237, 280, 280, 282, 285, 294, 294, 296, 299, 317, 319, 319, 319–320, 322, 327, 335–336, 338, 364, 367–369, 384, 390, 413, 430, 77, 80–82
packages/perennial-extensions/contracts/interfaces
   IMultiInvoker.sol100%100%100%100%
packages/perennial-extensions/contracts/types
   TriggerOrder.sol78.26%62.50%100%94.44%34–35, 61–68

@github-actions
Copy link

github-actions bot commented Sep 4, 2023

[Vault] Unit Test Coverage Report

Coverage after merging britz-add-margin into main will be
30.56%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/perennial-vault/contracts
   Vault.sol0%0%0%0%100, 106, 112–113, 121–122, 131, 133, 133, 133, 140, 142, 142, 142, 147, 147–148, 150–151, 151, 151, 154, 160, 160, 160–161, 161, 161, 163, 165–167, 174, 174–176, 184, 184, 184, 186–190, 195, 195–197, 203–204, 209, 209–212, 219, 219–221, 223–225, 238, 238–240, 242–245, 251–252, 252, 252–255, 257, 275, 275, 275–276, 276, 276, 279, 279, 279–281, 281, 281–283, 283, 283–285, 285, 285–287, 287, 287–289, 289, 289–290, 292, 292, 292, 295, 298–300, 303–305, 307, 321, 321, 321–323, 325, 325, 325, 330–331, 346, 350–353, 355, 361, 364, 364, 364, 367, 367, 367, 371–373, 386, 388, 388, 388, 388, 388, 390, 396–397, 397, 397–400, 400, 400–401, 408, 411, 413, 423, 437, 439–442, 444, 446–449, 452–453, 455–458, 461–462, 465–466, 469, 469, 469–471, 478, 478, 478–480, 487, 487, 487–489, 496, 496, 496, 498–501, 503, 503, 503, 503, 503, 505, 510, 517–519, 529–531, 533–535, 59, 59–60, 62–66, 72, 79, 86, 93
   VaultFactory.sol0%0%0%0%30–31, 35, 35–36, 48, 48, 50, 54–57, 59, 66–67
packages/perennial-vault/contracts/interfaces
   IVault.sol100%100%100%100%
   IVaultFactory.sol100%100%100%100%
packages/perennial-vault/contracts/lib
   StrategyLib.sol0%0%0%0%101–104, 106, 108–109, 111–112, 126–128, 137, 64–66, 68, 70–73, 76, 80, 82, 82, 82, 82, 82–83, 85, 87
packages/perennial-vault/contracts/types
   Account.sol100%100%100%100%
   Checkpoint.sol100%100%100%100%
   Mapping.sol100%100%100%100%
   Registration.sol100%100%100%100%
   VaultParameter.sol100%100%100%100%

@github-actions
Copy link

github-actions bot commented Sep 4, 2023

[Oracle] Unit Test Coverage Report

Coverage after merging britz-add-margin into main will be
79.22%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/perennial-oracle/contracts
   Oracle.sol100%100%100%100%
   OracleFactory.sol100%100%100%100%
packages/perennial-oracle/contracts/interfaces
   IOracle.sol100%100%100%100%
   IOracleFactory.sol100%100%100%100%
   IPythFactory.sol100%100%100%100%
   IPythOracle.sol100%100%100%100%
packages/perennial-oracle/contracts/pyth
   PythFactory.sol57.14%31.82%77.78%72%100, 106, 117, 44, 53, 60–61, 75, 84, 89, 89–91, 91, 91–92, 92, 92–93, 93, 93, 95
   PythOracle_Arbitrum.sol0%100%0%0%15, 20
   PythOracle_Optimism.sol0%100%0%0%15, 20
   PythOracle.sol53.33%35.42%73.33%63.16%114–115, 121, 121, 121, 132, 137–138, 144, 148–149, 151, 151, 151, 154, 154, 154, 177, 177, 177, 182–183, 186, 189, 189, 189–190, 193–194, 194, 194, 196, 196, 196–197, 197, 197–199, 199, 199, 199, 199, 201–202, 244, 66, 70, 76, 81, 83, 93

@github-actions
Copy link

github-actions bot commented Sep 4, 2023

[Core] Integration Test Coverage Report

Coverage after merging britz-add-margin into main will be
92.54%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/perennial/contracts
   Market.sol75.50%55.88%88.57%84.85%100–101, 106, 113, 120–122, 131, 133, 133, 133–134, 134, 134–136, 136, 136–137, 137, 137, 139, 146, 146, 146, 148–150, 155, 157–158, 160–161, 252–254, 393, 438, 477–478, 478, 478, 478, 487–488, 493–494, 496–497, 501, 507–508, 508, 517, 517, 517, 521, 526, 537, 543–544, 561–562, 60, 613, 618, 83, 92, 99, 99
   MarketFactory.sol69.70%50%83.33%80%37, 48, 57–58, 64, 66, 72, 75–76
packages/perennial/contracts/interfaces
   IMarket.sol100%100%100%100%
   IMarketFactory.sol100%100%100%100%
   IOracleProvider.sol100%100%100%100%
   IOracleProviderFactory.sol100%100%100%100%
   IPayoffProvider.sol100%100%100%100%
packages/perennial/contracts/types
   Global.sol78.57%50%100%100%114–125
   Local.sol80%56.25%83.33%95.65%127–132, 89, 97
   MarketParameter.sol69.57%40.91%100%95%112, 114–115, 117, 119, 121, 121, 121, 121, 133–137
   OracleVersion.sol100%100%100%100%
   Order.sol88.46%70%100%100%73, 79, 98
   Position.sol89.06%60%97.14%98.41%200, 218, 275, 478–487
   ProtocolParameter.sol75%50%100%100%59–60, 66–70
   RiskParameter.sol72.13%50%100%100%142, 147, 152, 154, 159, 161, 163, 165, 167, 169, 179–185
   Version.sol90.18%70.59%100%98.57%192–193, 361–369

@github-actions
Copy link

github-actions bot commented Sep 5, 2023

[Extensions] Integration Test Coverage Report

Coverage after merging britz-add-margin into main will be
99.25%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/perennial-extensions/contracts
   MultiInvoker.sol96.82%91.46%100%100%156, 225, 282, 296, 364, 384, 430
packages/perennial-extensions/contracts/interfaces
   IMultiInvoker.sol100%100%100%100%
packages/perennial-extensions/contracts/types
   TriggerOrder.sol89.13%83.33%100%94.44%34–35, 61–63

@github-actions
Copy link

github-actions bot commented Sep 5, 2023

[Vault] Integration Test Coverage Report

Coverage after merging britz-add-margin into main will be
98.96%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/perennial-vault/contracts
   Vault.sol97.41%95.95%97.06%98.15%209, 209–212, 292
   VaultFactory.sol89.47%50%100%100%35, 48
packages/perennial-vault/contracts/interfaces
   IVault.sol100%100%100%100%
   IVaultFactory.sol100%100%100%100%
packages/perennial-vault/contracts/lib
   StrategyLib.sol100%100%100%100%
packages/perennial-vault/contracts/types
   Account.sol82.86%50%100%100%126–131
   Checkpoint.sol88.64%68.75%100%100%132, 186, 224–231
   Mapping.sol95.12%80%100%100%100, 95
   Registration.sol81.82%50%100%100%41–42
   VaultParameter.sol87.50%50%100%100%31

@github-actions
Copy link

github-actions bot commented Sep 5, 2023

[Core] Unit Test Coverage Report

Coverage after merging britz-add-margin into main will be
99.77%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/perennial/contracts
   Market.sol99.34%98.04%100%100%517, 83
   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%
   IPayoffProvider.sol100%100%100%100%
packages/perennial/contracts/types
   Global.sol100%100%100%100%
   Local.sol95.56%100%83.33%95.65%97
   MarketParameter.sol100%100%100%100%
   OracleVersion.sol100%100%100%100%
   Order.sol100%100%100%100%
   Position.sol100%100%100%100%
   ProtocolParameter.sol100%100%100%100%
   RiskParameter.sol96.72%94.12%100%100%180–181
   Version.sol100%100%100%100%

Base automatically changed from britz-fix-failing-ci to main September 5, 2023 02:20
@github-actions
Copy link

github-actions bot commented Sep 5, 2023

[Oracle] Integration Test Coverage Report

Coverage after merging britz-add-margin into main will be
78.57%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
packages/perennial-oracle/contracts
   Oracle.sol33.75%30%41.67%34.21%100, 100, 100, 102–103, 103, 103, 105, 107, 107, 107–108, 115, 118–119, 119, 119, 121, 126, 126, 126–128, 20, 30, 37, 37–38, 40, 44–45, 52–53, 58, 63, 70, 70, 70–73, 73, 73–74, 76, 82
   OracleFactory.sol58.33%40.63%70%73.33%103–105, 105, 105–106, 112, 112, 112–113, 33, 41, 48, 48–50, 57–59, 62, 73–75, 78, 85, 94–95
packages/perennial-oracle/contracts/interfaces
   IOracle.sol100%100%100%100%
   IOracleFactory.sol100%100%100%100%
   IPythFactory.sol100%100%100%100%
   IPythOracle.sol100%100%100%100%
packages/perennial-oracle/contracts/pyth
   PythFactory.sol89.29%72.73%100%100%106, 117, 44, 53, 60, 89
   PythOracle_Arbitrum.sol100%100%100%100%
   PythOracle_Optimism.sol100%100%100%100%
   PythOracle.sol98.33%95.83%100%100%132, 231

@arjun-io arjun-io self-requested a review September 5, 2023 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants