synthetix icon indicating copy to clipboard operation
synthetix copied to clipboard

NO MERGE -- Upgradable FuturesV2 (with hot fixes)

Open leomassazza opened this issue 2 years ago • 1 comments

Make current futures system upgradable, add a self-migrate mechanism so that users can migrate their positions from the older version to this one and add some hot/quick fixes to improve usability while waiting for the migration to V3.

Stage 0 is upgrading current Futures contracts to be upgradable and maintainable. The main architectural changes are:

  • Remove all state from market contracts and move to a specific contract that can be migrated
  • Add a proxy in front of the FuturesMarket
  • Split the main contract to make it fit in the max contract size

In order to achieve the 3 points above (mostly because of the need to split the FuturesMarkets), this PR:

  • introduces a new set of contracts to keep the current version of Futures untouched. The new contracts names are based on FuturesV2 prefix.
  • introduces a new Proxy (ProxyFuturesV2.sol) based on Proxy.sol and taking the routing v3 concepts.
  • introduces a shared state component (StateShared.sol) based on State.sol that adds the ability to use a state contract from more than one associatedContract.
  • copies the classic Futures tests adapting them to the new architecture
  • adds new tests to include coverage for the new stuff.
  • adds deployment scripts to cope with FuturesV2 architecture.

TODO List:

  • [x] Create a copy of contracts for FuturesV2 (same functionality)
  • [x] Update the architecture so that FuturesV2 is upgradable/maintainable
    • [x] Split FuturesV2Market into implementation and state
    • [x] Add a Proxy in front of the the implementation
    • [x] Update current tests to use new architecture
    • [x] Split contract to fit in size limits
      • [x] Improve proxy
      • [x] Views
      • [x] Mutations (main txs)
      • [x] NextPriceOrders
    • [ ] Clean/Update comments
    • [ ] Add tests for new contracts
      • [ ] ProxyFuturesV2
      • [ ] StateShared
      • [ ] Security of sub contracts
    • [ ] Update deploy tasks with new architecture
  • [ ] Add migration mechanism

Feature Branches

  • [ ] Feature/Fix: Price Correction
  • [ ] Feature/Fix: Slippage Protection Mechanism
  • [ ] Feature/Fix: Upgrade Funding Mechanism
  • [ ] Feature/Fix: Fix Maker/Taker for cross-sides orders
  • [ ] Feature/Fix: Make Next Price Order time based
  • [ ] Feature/Fix: (optional) Margin with other synths
  • [ ] Feature/Fix: (optional) Intend to trade

leomassazza avatar Sep 05 '22 15:09 leomassazza

Codecov Report

Merging #1893 (efbcef6) into develop (20bb111) will increase coverage by 0.06%. The diff coverage is 97.47%.

:exclamation: Current head efbcef6 differs from pull request most recent head e5b82d4. Consider uploading reports for the commit e5b82d4 to get more accurate results

@@             Coverage Diff             @@
##           develop    #1893      +/-   ##
===========================================
+ Coverage    95.51%   95.57%   +0.06%     
===========================================
  Files          111      119       +8     
  Lines         2697     2915     +218     
  Branches       815      872      +57     
===========================================
+ Hits          2576     2786     +210     
- Misses         121      129       +8     
Impacted Files Coverage Δ
contracts/EmptyFuturesMarketManager.sol 0.00% <0.00%> (ø)
contracts/PerpsV2MarketDelayedOrdersBase.sol 85.71% <85.71%> (ø)
contracts/PerpsV2MarketSettings.sol 95.08% <95.08%> (ø)
contracts/PerpsV2MarketViews.sol 96.96% <96.96%> (ø)
contracts/FuturesMarketManager.sol 100.00% <100.00%> (ø)
contracts/MixinPerpsV2MarketSettings.sol 100.00% <100.00%> (ø)
contracts/PerpsV2ExchangeRate.sol 100.00% <100.00%> (ø)
contracts/PerpsV2Market.sol 100.00% <100.00%> (ø)
contracts/PerpsV2MarketBase.sol 100.00% <100.00%> (ø)
contracts/PerpsV2MarketData.sol 100.00% <100.00%> (ø)
... and 6 more

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov[bot] avatar Sep 05 '22 19:09 codecov[bot]

https://github.com/Synthetixio/synthetix/runs/9300428570 This has been running for a while now

Started 2d 7h 21m 54s ago

😱

davidvuong avatar Nov 06 '22 23:11 davidvuong

~I don't think the DelayedOrder changes in https://github.com/Synthetixio/synthetix/pull/1899 were merged correctly. There are still instances where NextPrice is still present. Same with the new funding model https://github.com/Synthetixio/synthetix/pull/1914. Changes to incorporate velocity don't seem to be present here.~

Nvm the the diff on #1921 was wrong.

davidvuong avatar Nov 06 '22 23:11 davidvuong