Skip to content

Futures liquidation fee update#1594

Merged
artdgn merged 16 commits intofutures-implementationfrom
futures-liquidation-fee-update
Nov 16, 2021
Merged

Futures liquidation fee update#1594
artdgn merged 16 commits intofutures-implementationfrom
futures-liquidation-fee-update

Conversation

@artdgn
Copy link
Copy Markdown
Contributor

@artdgn artdgn commented Nov 5, 2021

Updates the futures liquidation related logic for the first two items of Synthetixio/issues#352:

  1. Proportional liquidation fee - to incentivise liquidations of larger positions first. Tentatively set to 35 bps.
  2. Proportional liquidation margin buffer - to prevent negative margin liquidation, and to allow proportional fee to be paid to the fee pool. Tentatively set at 25 bps. If this buffer will not be needed in practice for safety (or for fees), the value can be set to 0 in the future.

These two values now allow controlling the proportional liquidation margin, and the allocation of that margin upon liquidation to the liquidator and fee pool.

Other important changes in this PR:

  • Adding the parameters to FuturesMarketSettings: liquidationFeeBPs and liquidationBufferBPs
  • Adding new views to FuturesMarket: liquidaionFee and liquidationMargin
  • Changing the logic of _liquidationPrice to calculate unrecorded funding using the current price.
  • Changing the event and debt adjustment during _liquidatePosition to use the current price instead of the liquidationPrice (which may be higher or lower than actual price at that time, depending on the parameters, buffer, and oracle price).
  • Sending any positive remainder of the margin to Fee Pool after deducting the liquidationFee (that goes to liquidator).

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 5, 2021

Codecov Report

Merging #1594 (a472c96) into futures-implementation (8defb47) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@                    Coverage Diff                     @@
##           futures-implementation    #1594      +/-   ##
==========================================================
+ Coverage                   93.87%   93.91%   +0.03%     
==========================================================
  Files                          85       85              
  Lines                        2058     2071      +13     
  Branches                      627      629       +2     
==========================================================
+ Hits                         1932     1945      +13     
  Misses                        126      126              
Impacted Files Coverage Δ
contracts/FuturesMarketData.sol 100.00% <ø> (ø)
contracts/FuturesMarket.sol 98.42% <100.00%> (+0.09%) ⬆️
contracts/FuturesMarketSettings.sol 100.00% <100.00%> (ø)
contracts/MixinFuturesMarketSettings.sol 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8defb47...a472c96. Read the comment docs.

@artdgn artdgn changed the base branch from futures-rename-parameters to futures-implementation November 5, 2021 05:02
@artdgn artdgn force-pushed the futures-liquidation-fee-update branch from 4d4e843 to e5b6b1f Compare November 5, 2021 05:15
@artdgn artdgn requested review from 0xclem, jacko125, liamzebedee and zyzek and removed request for 0xclem, liamzebedee and zyzek November 5, 2021 05:21
// profitLoss = (price - last-price) * positionSize
// price = lastPrice + (liquidationMargin - margin) / positionSize - netFundingPerUnit
int result =
int(position.lastPrice).add(int(liqMargin).sub(int(position.margin)).divideDecimalRound(positionSize)).sub(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This may be a dumb question but I definitely don't claim to be an expert in this area, so please, educate me. Why use the lastPrice here when we calculate the liqMargin above using the currentPrice?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

According to the derivation in the comments above, lastPrice is used in order to calculate the profit / loss, which is (futurePrice - lastPrice) * positionSize (which was the price the position was opened / updated at). This is because the formula is trying to solve for the futurePrice at which the position will be liquidatable. Using currentPrice would give incorrect P&L w.r.t. to position opening price (at which point the "the loan" from the debt pool was taken).

Liquidation margin is calculated using the current price because it's the best estimation we can do currently - because we can't really solve for the actual future liquidation margin because we don't know how funding in the future will affect it (because it depends on 1) time passage and future skew 2) at what times it's being recorded due to other transactions).

Previously liquidation margin was a constant parameter, but making it proportional to price & position introduces this imprecision in solving for liquidation price for the future.

The imprecision is not an issue for the actual liquidation transaction - because then futurePrice is currentPrice. It's also small when calculated close to the possible liquidation time.

The comments above the code are using trying to give more details about the derivation, but probably can be improved, any idea for what extra details needs to go there?

Copy link
Copy Markdown
Contributor Author

@artdgn artdgn Nov 11, 2021

Choose a reason for hiding this comment

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

TL;DR: I think both approaches make some sense, but both have drawbacks as well. I think the new one has better practical tradeoffs while not sacrificing any liquidation correctness.

Agree on the crux of the difference

I agree that the core difference is due to considering everything in terms of current price and current time, instead of "time traveling". And that everything should be consistent.

I've switched to using current instead of time travelling because:

  • The scenario of "liquidatable in the past, but not right now" was not really addressed because the contract doesn't have that past information during the liquidation tx (I think the SIP mentioned liquidators passing in the funding index, but it's not in the contract - liquidation method only has account as input).
  • Time traveling is more difficult to reason about and test exhaustively. Single time frame is easier to understand, discuss, and test. So from the egineering POV, simpler code, that still performs the important bit correctly (liquidation itself) may be preferrable to a more elegant code that is harder to maintain.
  • Previous time traveling logic relied on some assumptions of 1) funding not being recorded until liquidation 2) no time passing until liquidation. Which works well in testing scenario (because we can setPrice() for next second, and have no other transactions happen), but would still have incorrect liquidation price for the realistic scenario (of price moving at real-world pace, and funding accruing and being recorded until actual liquidation).

Disagree that there are scenarios where liquidations are missed

I think there are some tradeoffs here, and I really liked the elegance of being able to derive the exact price for testing, but I think the simplicity and separation of concerns (e.g. not having to re-derive formulas in liquidation price due to liquidation fee logic changes) felt like a better tradeoff if liquidations can happen correctly in both ways.

But with this system currentPrice can still be substantially below the true first liquidation price, for example if the price is moving quickly or if liquidation is slow for some reason

In this scenario, both approaches would trigger liquidation in the same way it seems. Or do you see a scenario at which the new method doesn't liquidate a position that the previous method would? (Keeping in mind that liquidation keeper only passes the account as input, without funding index or oracle round ID).

Disagree about using a more precise calculation: it would not be more precise in practice, and it would be more complicated

That precise computation is actually still possible in the proportional buffer case, though because of the max it needs two liquidation price formulae and a case analysis. I'll send the derivation out of band.

Thanks for the calculation. There are two reason's I'd be reluctant to implement it:

  1. The liquidation margin is slightly incorrect (it assumes the outer max() as proposed in another comment) and would require doing differently for the current liquidation margin (with inner max()).
  2. It would make the code quite a bit more complex, and would make the manual calculations necessary for maintaining the test cases more complex as well.
  3. It would strongly couple the liquidation price logic to the liquidation fee logic, which now can be encapsulated each in its own method.
  4. It would make future changes to the code of either the price, the fee, or the margin very hard to reason and maintain (because of the combination of coupling and complexity of the calculation).

This might be worth it, in my opinion, if the liquidations would happen more correctly, but it seems to me that when using currentPrice the liquidation itself would happen correctly with both versions, and the only downside to the imprecision is the over-conservative estimation of future hypothetical liquidation price, which isn't too bad.

Why this "imprecision" for the hypothetical price is not harmful

This over-conservative estimation may actually have usability advantages, because e.g. the current liquidation price for a long is returned slightly higher than actual future liquidation price, which is better than the other way arround (so e.g. the UI will say liquidation price 200, where in fact you'll be liquidated at 195, which is better the the reverse).

Copy link
Copy Markdown
Contributor

@zyzek zyzek Nov 11, 2021

Choose a reason for hiding this comment

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

Since the _canLiquidate function does not actually use the _liquidationPrice logic, I agree that positions will always liquidate at the correct times. I also agree with all points about complexity of the code.

The only thing I really worry about is the debt pool impact. If a position is liquidated at the current price, and that price is substantially below the "true" liquidation point (in the long case), then less debt will be removed from the debt correction by the liquidation than ought to have been, since the position's notional value is evaluated to be lower at liquidation.
I imagine in most cases this will be negligible but could get larger the longer a position is unliquidated and the faster prices are moving, and I wonder about the cumulative impact of many liquidations over time. Since using the current price is basically doing the same thing as other margin exchanges with respect to liquidation point, then perhaps this is an argument for doing as they do with maintenance margin and starting with a nonzero value for the buffer parameter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, will have a more thorough think through these scenarios in terms of debt and post back my conclusions here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'll add that other than this last point, I'm more or less satisfied that the PR looks pretty solid. As long as the debt considerations are being kept in mind, I'll leave it to full-time contributors for further review and approval (I haven't looked at test cases, config files and so on).

Copy link
Copy Markdown
Contributor Author

@artdgn artdgn Nov 12, 2021

Choose a reason for hiding this comment

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

Had a deeper look into the debt calculations:

  1. It seems that for the subject of liquidations, the liquidation price actually makes no difference for the debt calculations. This is because the new position is of 0 size and 0 margin, so the price used doesn't matter. So the new position adds no debt and the old position's debt is subtracted at its last price.
// in _liquidatePosition
        _applyDebtCorrection(
            Position(0, 0, 0, price, fundingIndex),
            Position(0, position.margin, positionSize, position.lastPrice, position.fundingIndex)
        );

// _positionDebtCorrection

    function _positionDebtCorrection(Position memory position) internal view returns (int) {
        return
            int(position.margin).sub(
                position.size.multiplyDecimalRound(int(position.lastPrice).add(fundingSequence[position.fundingIndex]))
            );
    }

// _applyDebtCorrection

    function _applyDebtCorrection(Position memory newPosition, Position memory oldPosition) internal {
        int newCorrection = _positionDebtCorrection(newPosition);
        int oldCorrection = _positionDebtCorrection(oldPosition);
        _entryDebtCorrection = _entryDebtCorrection.add(newCorrection).sub(oldCorrection);
    }
  1. Unrelated to the liquidation related debt calculation I don't really understand the role of the funding rate component of the debt correction calculation. It seems to me that the FR shouldn't be included in it. Because for a new position - there is no funding component in the debt added (the position is new), and for a modified position the funding is already counted in the updated margin along with the P&L (so it's double counted?). So I think it should probably be removed. I'll follow up on that out of band and if needed it will be a separate PR.

@artdgn artdgn requested a review from liamzebedee November 10, 2021 02:14
uint proportionalFee = _abs(positionSize).multiplyDecimalRound(price).multiplyDecimalRound(_liquidationFeeRatio());
uint minFee = _minLiquidationFee();
// max(proportionalFee, minFee) - to prevent not incentivising liquidations enough
return proportionalFee > minFee ? proportionalFee : minFee; // not using _max() helper because it's for signed ints
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Feels like the comment here at the end of line isn't needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the comment is there because it was suggested to use _max() in the reivew, and without this comment someone might have the same idea in future - and the comment will spare them the trouble :)

Copy link
Copy Markdown
Contributor

@jacko125 jacko125 left a comment

Choose a reason for hiding this comment

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

Happy with the changes. What are the default liquidation fee ratio % and buffer % in mind that we will set for deployment ? And then these can be added to sip-80

@artdgn
Copy link
Copy Markdown
Contributor Author

artdgn commented Nov 12, 2021

Happy with the changes. What are the default liquidation fee ratio % and buffer % in mind that we will set for deployment ? And then these can be added to sip-80

Yeah the sip will need to be updated, but perhaps worth to wait to make a single update with all the changes in this task.

The values I've set right now is:

  • 35 bps for fee incentive (so $35 for each 10K in notional risk).
  • 25 bps for buffer. The logic is that if actual liquidation price is on average 0.5% worse than the first liquidation price - the stakers will not be impacted.

@artdgn artdgn merged commit 5cdbb23 into futures-implementation Nov 16, 2021
jacko125 added a commit that referenced this pull request Mar 13, 2022
* Futures closure fee (#1417)

* kovan-ovm-futures (refactored) (#1400)

* Add confirmation and liquidation booleans to futures position data. (#1424)

* add missing chainlink feeds to kovan-ovm-futures

* re-run deployment with correct network set

* Add global futures settings to data contract. (#1431)

* Futures markets respect fee reclamation. (#1436)

* Futures markets respect fee reclamation.

* Check necessity of reclamation on reclaim value rather than number of entries settled.

* Fix merge history for futures-implementation (#1445)

* Alioth release (#1263)

* Remove bridge migrator (#1257)

* Skips multicollateral prod tests if max debt has been reached (#1259)

* SIP-136: MultiCollateral/CollateralEth debt is not excluded correctly from debt calculations (#1243)

* SIP-112: EtherWrapper (#1178)

* Deploy 2.45 to kovan (#1260)

* Prepublish step

* 2.45.0-alpha

* set mint fee and burn fee per sccp 100

Co-authored-by: Alejandro Santander <Palebluedot@gmail.com>
Co-authored-by: Synthetix Team <team@synthetix.io>
Co-authored-by: Jackson C <jackosmacko@gmail.com>

* Introducing new integration tests in CI (#1287)

* Introducing integration tests in CI

* Improved integration tests in CI and removed redundant prod tests

* Bugfix on integration test task

* More verbose on deployer error

* Refactoring of Exchanger.sol to reduce size on OVM (#1291)

* Minor fix for integration tests (#1295)

* Clean state on dual integration tests plus slightly better exchange tests

* Minor fix to integration tests

* Disable some exchanging integration tests for now

* Extra prod tests (#1299)

* Add issuance prod tests

* Add erc20 behavior

* Tweaks on incoming integration tests

* Minor fix to integrationt ests

Co-authored-by: Alejandro Santander <Palebluedot@gmail.com>

* Audit feedback and spring cleaning (#1300)

* Port more integration tests (#1288)

* Basic integration tests for L2 deposits

* Basic integration tests for L2 deposits

* Polish deposit integration tests

* Progress porting withdrawal integration tests

* Working withdrawals in new integration tests

* Using watcher tool more

* Unify action and actionTo in integration tests

* Progress porting integration tests

* Remove comment

* Implemented exchanges in new integration tests

* Bugfix in integrationt est task

* Basic forking in integration tests

* Include fork tests in CI

* Minor fixes for prod tests

* port migrateEscrow test to integration dual

* Fix CI

* Fix CI

Co-authored-by: Leonardo Massazza <lmassazza+github@gmail.com>
Co-authored-by: Yannis <i.stamelakos@gmail.com>

* Better way to get SNX in integration tests (#1303)

* Better way to get SNX

* 2192

* Introduces forking via integration tests (#1307)

* Introduces forking with integration tests

* Compile and deploy on fork tests

* Fix old ovm prod tests

* Replace web3 with ethers in deployment (#1271)

* add wrapper object to hold web3 and ethers

* Replace web3-utils with ethers

* - replace web3.utils with ethers counterpart
- create account with ethers instead of web3

* corrections to failed tests

* propagate Deploy changes fix (test:publish green)

* document the provider addition to Deployer

* document the provider addition to Deployer

* fix require

* fix require

* Clean install

* Update to develop

Co-authored-by: Alejandro Santander <Palebluedot@gmail.com>

* Updates optimism dependencies (#1308)

* Updated optimism deps

* Update usage of dep in code

* Add hardhat-ethers dep required by smock

* Add await in unit test

* Removed @gas-skip (#1309)

* Updated optimism deps

* Update usage of dep in code

* Add hardhat-ethers dep required by smock

* Removed @gas-skip

* Add await in unit test

* Disables prod tests from CI (#1311)

* Reordering the deploy script for sanity (#1304)

* Add integration tests for settle and claim (#1310)

* Support settlements in exchanging behavior

* Testing claims in integration tests

* Address PR feedback, increase timeouts, improve test for forking

* Bigger tolerance for debt comparison

* Approve bridge tokens during bootstrap

* Add SynthsUSD integration (L1 and L2) tests (#1312)

* Add support to SynthsUSD in L1 and L2 integration tests

* Add support to SynthsUSD in L1 and L2 integration tests

* style fixes

Co-authored-by: Alejandro Santander <Palebluedot@gmail.com>

* Port migrateEscrow and depositAndMigrateEscrow tests  (#1306)

* ported. Some tests still failing

* wip

* migrateEscrow test ported

* accept multiples hashes in watchers

* Reduce migrateEscrow dual test to dual scope

* ported depositAndMigrateEscrow test

* update test wording

Co-authored-by: Alejandro Santander <Palebluedot@gmail.com>

* Migration for bulk staking reward upgrade (#1301)

* Deleted everything related to prod tests (#1315)

* Adds ether wrapper integration tests (#1319)

* Basic integration tests for ether wrapper

* Fix timeout in integration tests

* Abstract eth wrapper behavior in integration tests

* Support ether wrapper integration tests in mainnet forks

* Pin ops to a particular commit that is known to work in CI

* Processed Leo's feeedback on PR

* Enables separate folder compilation for integration tests (#1322)

* Enables separate folder compilation for integration tests

* Clean install

* Merge all integration test tasks into one (#1323)

* Remove web3 from the deploy script test (#1328)

* Progress removing web3 from test for deploy script

* Progress removing web3 from test for deploy script

* Almost done removing web3 from deploy tests

* Add optimism scripts to run Optmism via hardhat (#1324)

* Add optimism scripts to npm

* fix variable naming

* Add harhat task to build and start ops

* remove ops scripts from packages.json

* - check status to run the right steps
- order jobs
- cleanup messages

* Update circleCI

* change docker command to test on circleCI

* keep chain atached and add detach option

* Tweak CI for integration tests

* Keep ops start task open

Co-authored-by: Alejandro Santander <Palebluedot@gmail.com>

* Unpins the usage of the Optimism ops tool and starts managing L2 gas (#1331)

* Removes web3 from nominate script (#1332)

* Progress removing web3 from nominate script

* Applies nominate test to L2

* Ported nominate script to ethers

* Fix

* Removed web3 from settle script (#1334)

* Removed web3 from extract-staking-balances (#1335)

* Remove web3

* Remove wallet (only read from contracts)

* Removes web3 from the owner script (#1336)

* Using owner script in integration tests

* Removed web3 from owner script

* Manually setting isContract in owner script

* Add caching of docker layers on integration tests job (#1333)

* remove docker prune from ops tasks

* add cache for optimism build on integration-tests job

* add a check to execute deployments tests only if a deployment.json file changed (#1339)

* Removes web3 from the purge script (#1341)

* Support forks in purge-synths script

* Extract performTransactionalStep version for ethers

* Rename function to deprecate

* Minor fix

* Remove web3 from remove-fee-periods (#1342)

* wip commit

* wip commit

* wip

* wip

* Remove log line from script

* remove empty comment

* Add gas reporting job parallelization on CI (#1305)

* add task for merging gas reports files on CI

* add parallelized gas reports to unit tests

* update codechecks unit-test-gas-report name

* remove optimizer flag from unit tests

* remove test:gas script from package.json

* remove web3 references (#1344)

* SIP-150 Fix excluded debt calculation for partial snapshots. (#1340)

* SIP-145 Emit the proper cached debt number when debt snapshots are taken. (#1325)

* remove web3 from migrate-binary-option-markets (#1345)

* Fixing nominate to work locally and ethers fix (#1354)

* Introduces fast forwarding in L2 integration tests (#1343)

* Basic fast forwarding in L2 integration tests

* Replaced 'ignore' utils with fast forwarding in integration tests

* Clean install

* Undo changes to package lock file

* Pin ops version

* Avoid redundant heartbeats

* Fix and improve integration tests

* Add comment to test

* Update ops image

* Clear ops cache in CI

* Update watchers dep

* Hotfix for Optimism watchers

* Clean install

* Update to hardhat 2.3.x

* Clear ops tool cache

* Unpin ops

* Update ops cache

* Attach ops output

* Debugging Optimism messenger watchers

* Listen to interactions with messenger on blocks

* Keep withdraw tests open

* Implementing a completely patched ops watcher

* Tidy ups

* remove only in tests

* Disabled ops cache

* Restored ops caching

* Quiet

* Bugfix

* Debug optimism in l2 standalone integration tests

* Cleanups

* Adds integration tests for opening and closing a loan (#1330)

* Resolves conflict

* Updates ignore waiting period to new pattern

* Deploy EmptyEtherWrapper (#1349)

* EmptyEtherWrapper

* deploy EmptyEtherWrapper

* ignore EmptyEtherWrapper for coverage

* Use simple synths in local-ovm

* Bugfix on ops tool task

Co-authored-by: Alejandro Santander <Palebluedot@gmail.com>

* remove web3 from checkAggregatorPrices (#1353)

Co-authored-by: Alejandro Santander <Palebluedot@gmail.com>

* Unify wallet creation and ensure .address is always present (#1357)

Co-authored-by: Alejandro Santander <Palebluedot@gmail.com>

* Support for testnet forking (#1359)

* Allow private key overrides in local and fork mode (#1360)

* Fix for SupplySchedule - must use the ERC20 proxy (#1338)

* Adding new synth suspension reason for index rebalancing and using testnet checksum address

* SCCP-98 DEFI rebalance (#1364)

* Prepublish step

* 2.45.3

* Refresh ops cache (#1368)

* Upgrading etherscan links to optimistic explorer when required (#1369)

* Ethers overrides gasLimit, not gas (#1366)

* Adds documentation for integration tests (#1367)

* Add documentation for integration tests

* Update integration tests README

* Updating releases for Alnitak (#1363)

* Remove web3 from persist-tokens. (#1352)

* remove from persist-tokens. Missing one command

* WIP Commit (to stage the branch). Need to replace SetContenthash with our own implementation

* wip

* Remove web3 dependency (setContenthash doesn't work)

* Remove commented out code and useless interaction

Co-authored-by: Alejandro Santander <Palebluedot@gmail.com>

* Incorporate synthetix-cli interactive-ui as a `npx hardhat interact` task (#1365)

* add interactive ui hardhat task

* update pacakge-lock with a clean install

* Minor tidy ups

* Remove redundant utils

Co-authored-by: Alejandro <palebluedot@gmail.com>

* Adding solidity output to deploy script (#1313)

* Simplify conditional logic of generate solidity (#1378)

* Alnitak release kovan (#1379)

* Prepublish step

* 2.46.0-alpha

* Adding EtherWrapper for L2 to deploy empty and SystemSettings for Etherwrapper settings (#1380)

* Alnitak release kovan optimism (#1381)

* Prepublish step

* 2.46.0-alpha-ovm

* Fixing local dev to properly only deploy WETH the first time (#1384)

* Removing 145 and 150 from Alnitak (#1386)

* Fix fork-tests to work and surface errors correctly (#1385)

* OVM gas limit fixes (#1382)

* Mainnet deploy of Alnitak contracts and migration (#1383)

* Prepublish step

* 2.46.0

* Alnitak release optimism (#1390)

* Prepublish step

* 2.46.0-ovm

* Fixes integration tests on CI (#1392)

* Makes l2 standalone integration tests pass

* Refresh ops tool cache in CI

* Possible fix to hardhat ops task

* Undo bad fix, but with small tidy up

* Try to build ops image manually

* Update CI build

* Small bugfix on ci

* Another attempt at building ops tool on ci

* Undo all changes to CI

* Disabled ops tool in CI

* Disable ops tool build

* Showing a different name while integration tests are simplified

* Pins a newer ops tool version

* Re-enable ops-tool in CI (#1395)

* use docker 20.10.6 in CI

* duh...

* fix bootstrap.js issue on dual

Co-authored-by: Alejandro Santander <Palebluedot@gmail.com>
Co-authored-by: Synthetix Team <team@synthetix.io>
Co-authored-by: Jackson C <jackosmacko@gmail.com>
Co-authored-by: Justin J. Moses <justinjmoses@gmail.com>
Co-authored-by: justin j. moses <justin@synthetix.io>
Co-authored-by: Yannis <i.stamelakos@gmail.com>
Co-authored-by: Leonardo Massazza <lmassazza+github@gmail.com>
Co-authored-by: Matías Lescano <mjlescano@users.noreply.github.com>
Co-authored-by: Anton Jurisevic <zyzek@users.noreply.github.com>
Co-authored-by: David Goldberg <gberg1@users.noreply.github.com>

* Futures order slippage (#1446)

* add maxSlippage to submitOrder

This will be used to calculate an upper/lower bound for the price upon an order being confirmed.

* add slippage to calls

* failing test for confirmOrder slippage

* passing test for confirmOrder slippage

* fix some tests

* * fix/simplify slippage calc
* fix tests

* fix test

* convert slippage param to price bounds (min, max)

* fix tests

* test order min/max price in data contract

* canConfirmOrder respects max market size constraints + error management + order size/status (#1430)

* Futures: Market deployment and management scripts (#1440)

* add futures-markets.json to deploy configs

* load futures market settings from config

* remove FUTURES_ASSETS config var

* fix

* add futures-markets.json to deploy configs

* load futures market settings from config

* remove FUTURES_ASSETS config var

* fix

* wip

* wip2

* restore

* * modify publish script test to work with OVM
* add test for futures markets being added

* fix: use only hardhat for L2 tests

* publish script working for local-ovm

* add optimism folder to eslintignore file (#1406)

* restore publish script to original l1-only design

My original design was too complex for not much benefit, since most of the tests were skipped anyways.

* add l2 publish script test, as separate block below

This is a much cleaner diff that'll enable me to get this work out quicker.

* lint

* remove publish test block

I'll reintegrate this in another PR.

Co-authored-by: Matías Lescano <mjlescano@users.noreply.github.com>

* Richer Futures position and margin events (#1456)

* Futures documentation (#1460)

* Dead code cleanup. (#1462)

* Position ID, PositionOpened, PositionClosed added (#1461)

* Position ID, PositionOpened, PositionClosed added

* removed useless positionId variable

* PR fixes

* removing PositionOpened & positionClosed

* Adding new status to futures market interface

* test debug

* tests added

* Futures spot trades (#1477)

* Futures position details (#1479)

* Futures accessible margin (#1484)

* emit sizeDelta with PositionModified event (#1485)

* emit sizeDelta with PositionModified event

* fix

* sizeDelta -> tradeSize

This is clearer for liquidation flows

* Deploy kovan-ovm-futures v0.4.0 (Alpha) (#1487)

* remove price update constraint from order flow

* prepare-deploy

* add FuturesMarketSettings to releases

* deploy kovan-ovm-futures v0.2.0

* fixes

* unignore deployment.json

* add FuturesMarketSettings to releases

* prepare-deploy

* deploy kovan-ovm-futures v0.3.0

* Futures position details (#1479)

* Futures accessible margin (#1484)

* emit sizeDelta with PositionModified event

* emit sizeDelta with PositionModified event (#1485)

* emit sizeDelta with PositionModified event

* fix

* sizeDelta -> tradeSize

This is clearer for liquidation flows

* deploy kovan-ovm-futures v0.4.0

* test that npmignore will include deployment.json

NPM ignores files listed in gitignore which is a problem.

https://stackoverflow.com/questions/24942161/does-npm-ignore-files-listed-in-gitignore

Co-authored-by: Anton Jurisevic <zyzek@users.noreply.github.com>

* Fix futures position id management + tests. (#1492)

* fix slither crashing in CI and local (#1519)

 fix slither crashing in ci and local

#1519

* Adding gnosis safe multisend functionality to owner (#1513)

* Adding safe functionality from the gnosis SDK to the owner command
* Updating nominate command to use owner actions when not the owner

* SIP-135 Cleanup (#1522)

* Prepping for the Sargas (2.50) release to OVM (#1526)

* Sargas to be OVM only with 135, 142 and 174
* Adding missing SIP-140 from list

* Fixing settle for ethers (#1509)

* Reduce gas usage for opening loans (#1529)

* Print deploy param object value (#1534)

* add slither code check github integration (#1523)

* Refactor exceedsDebtLimit check (#1539)

* Removing unneeded kovan contracts (#1538)

* ci: lavamoat integration (#1517)

* CI: add codeql (#1544)

* Adds block tag parameter to interact task (#1528) (#1536)

* ci: slither github actions improvements (#1543)

* Removing integrationProxy from Proxyable  (#1521)

* up maxMarketValue

* Fix prepare deploy (#1548)

* Document debt cache (#1533)

* * conceptually document this function
* iterate on a simplified construction

* rewrite doc for current version, sans changes to logic

* document debt cache

* Updating packages for audits and temporarily disabling the audit check (#1553)

* redeploy again

* ci: fail audit on critical severity (#1557)

Signed-off-by: Jakub Mucha <jakub.mucha@icloud.com>

* ci: update docker containers to node@14.18 (#1558)

* chore: name entry added to lockfile in recent npm version
* ci: update docker containers to node@14.18

* Futures: merge develop (#1547)

* Update proportional skew funding calculation to use maxMarketValue an… (#1556)

* Update proportional skew funding calculation to use maxMarketValue and also cap maxMarketValue

* update funding rate skew tests and IFuturesMarket interface

* Futures min skew scale (#1561)

* use minSkewScale to control starting funding rate

* enable skipped tests

* increase testnet minSkewScale

* add test for minSkewScale regime transition

Co-authored-by: Arthur Deygin <29574203+artdgn@users.noreply.github.com>

* add verified details for some (not all) contracts

* only run if CollateralShort exists

* * Move "sources" into "sips"
* Add additional sources to SIP-80

* fix: disable WETH deployment on L2

* deploy kovan-ovm-futures v0.5.0

* add whitelist for transfering externstateToken (#1565)

* add whitelist for transfering externstateToken

* update require statement

* enable limited transfers on kovan-ovm-futures

* introduce LimitedTransferSynth, a clone of Synth with limited transfers according to whitelist
* polymorphic approach to deploying LimitedTransferSynth

Co-authored-by: liamzebedee <liamzebedee@yahoo.com.au>

* prepare-deploy kovan-ovm-futures v0.5.1

* prepare-deploy 0.5.2

We need to replace Issuer as the synths are being added there, not in Synthetix

* prepare-deploy 0.5.3

hack: deploy SynthRedeemer so we can get out-the-door

* deploy 0.5.3

* revert changes

* Deploy kovan-ovm-futures v0.5.0 (#1566)

* add verified details for some (not all) contracts

* only run if CollateralShort exists

* * Move "sources" into "sips"
* Add additional sources to SIP-80

* fix: disable WETH deployment on L2

* deploy kovan-ovm-futures v0.5.0

* prepare-deploy kovan-ovm-futures v0.5.1

* prepare-deploy 0.5.2

We need to replace Issuer as the synths are being added there, not in Synthetix

* prepare-deploy 0.5.3

hack: deploy SynthRedeemer so we can get out-the-door

* deploy 0.5.3

* revert changes

* add missing deployments to config.json so verify picks them up

* verified

* prepare-deploy 0.5.4

* deploy SynthsETH and SynthsUSD

* During deployment, ensure deprecated synths from Wezen have cache updated (#1564)

* Update configure loans interactionDelay (#1568)

* update deployer to support EIP-1559 (#1504)

* update deployer to support EIP-1559

updates `--gas-price` to be replaced with `--max-fee-per-gas` which specifies the maximum base fee paid on a transaction. Additionally, deployer may also specify `--max-priority-fee-per-gas` to specify a mining tip (default: 1 gwei)

If the network does not support 1559, the `gasPrice` is automatically determined by ethers.

For EIP-1559 support, ethers.js needed to be upgraded to 5.4.6

Co-authored-by: jj <jj@og.snxdao.io>

* futures listen to system and synth suspensions (#1530)

* Deploy kovan-ovm-futures v0.6.0 (#1570)

* log error here for better info

* upgrade deployer for OVM 2.0

* fix: update gas price

* prepare-deploy 0.6.0

* fix: rm WETH deploy

* fix url's to etherscan

* SIP-187 fix partial synth updates and debt cache updates (#1551)

* fix partial synth updates and debt cache updates

* Remove require check that cachedSum < Debt as excluded Debt can cause this to fail. Update calc of delta in new synths changed.

* * revert max market value to higher amount
* fix network key in deployment.json

* remove gasPrice overrides from simulate-deploy (#1573)

* Exchange rates circuit breaker refactor (#1540)

* SIP-182 Wrapper Factory (#1489)

Co-authored-by: Lecky <leckylao@gmail.com>
Co-authored-by: Mark Barrasso <4982406+barrasso@users.noreply.github.com>

* SIP-182 Audit feedback - allowance in constructor (#1584)

* Fix param spam during deployment (#1587)

* add missing data in position modified events (#1580)

* add expalantion about releases.json in readme (#1569)

Co-authored-by: Liam Zebedee <liamzebedee@yahoo.com.au>
Co-authored-by: jj <jj@og.snxdao.io>

* ci: use node 16 (LTS) (#1588)

* ci: use node@16

* ci: use new cache key

* chore: "name" missing in package-lock.json

* ci: generated new config

* chore: use node@16 by default

Signed-off-by: Jakub Mucha <jakub.mucha@icloud.com>

* Removing inverse synths (#1592)

* Ensuring SCCP-139 feeds are persisted to future ExchangeRates contracts (#1593)

* Futures rename parameters (#1595)

* Deploy kovan-ovm-futures v0.7.0 (#1589)

* log error here for better info

* upgrade deployer for OVM 2.0

* fix: load source for LegacyOwned

LegacyOwned is contained within legacy/

* remove ovm-specific logic around compilerversion metadata

Code is now compiled using the regular solc.

* update gas price again

* prepare-deploy

* deploy kovan-ovm-futures v0.7.0

* rm WrapperFactory from config

I copied these changes hackily across from develop. This snuck through

* contracts verified

* deploy kovan-ovm-futures v0.7.0 again

For some reason, LimitedTransferSynth wasn't deployed for SynthsUSD the first time

* update ops node

* use the optimismCommit in task-ops.js as a cache key

* Skip shorts integration tests when cannot open loans (#1597)

* Add default private key for local-ovm deploys (#1455)

* add default private key for local-ovm deploys

* fix: add useOvm

* Update ops node commit to working version in `develop`

* SIP-120: TWAP Exchange Function (#1127)

* Adding 6 more potential releases

* Helper script to distribute SNX/sUSD to accounts on kovan-futures-ovm (#1554)

* commit empty deployment.json for local-ovm so resolve will work

* move local-ovm network down

* iterate on local helper for bootstrapping

* working script to bootstrap local l2 account (aka snx-brrr)

* local script now supports specifying provider/snx-network/owner account

* use ensureBalance to get testnet SNX/sUSD for accounts

* refactoring: balances script

* log error here for better info

* upgrade deployer for OVM 2.0

* fix: update gas price

* prepare-deploy 0.6.0

* fix: rm WETH deploy

* update local dist script with whitelist

* revert

* rename file to match task

* Futures liquidation fee update (#1594)

* adding market debt explanation comments

* Fixing owner script to not submit multiple accept for dupe contracts

* Upgrading to OVM 2.0 (or the destruction of useless code) (#1598)

* Minor fixes for release history

* SIP-167 Introduces an L2 governance bridge (#1402)

* Removing mistake

* Fixes from menkalinan (#1608)

* Owner batch fixing
* Adding L2 owner

* Update OVM bytecode (#1613)

* Move debt snapshot to beforeEach block (#1616)

* Fix duplicate fee reporting on WrapperFactory (#1617)

* SIP-194 Fix Liquidations on L2 (#1621)

* Fix broken unit test (#1622)

* Futures next price mechanism (#1609)

* Futures remove closure fee and rounding (#1610)

* reduce storage variables sizes for gas savings (#1614)

* Ensuring job-compile size check matches build command (#1628)

* refactor views into mixin to reduce clutter (#1615)

* rename circuit breaker contracts (#1629)

* Adding exchange gas usage output

* Adding gas output to synth issue, burn and claim in int tests

* SIP-188: Add sETHBTC synth (#1618)

* add tests for debt cache when markets

* SIP-195: L2 CollateralEth Loans (#1632)

* Sip 196 remove internal oracle (#1636)

* Fix contracts compiling after merge

* Remove LimitedTransferSynth

* add liquidation tests in integration (#1625)

* use new `hardhat-interact` package instead of builtin (#1612)

* fix liquidations fork test fail (#1646)

* SIP-193 Reduce size for SystemSettings (#1627)

* Implement interface funcs for BaseDebtCache, EmptyCollateralManager, IExchanger interface cleanup

* Update configuration of loan and system settings (#1637)

* SIP-200: Fix FeePool Rewards Distribution (#1650)

* migration script helper allows deployment and staging of migration script call (#1652)

this should make releases a little easier and make it easier to utilize the migration script functionality of the deployer.

* deploy futures to kovan-ovm-futures and update configuration scripts

* fix shadowing in empty futures market

* fix circuit breaker tests

* remove deprecated setLastExchangeRateForSynth

* update fund local accounts script

* fix atomic exchange circuit breaker tests

* fix market settings and manager tests

* SIP-184 Dynamic Fees (#1649)

* fix status script and fund local accounts

* Take debt snapshot before funding local accounts (#1657)

* fix aggregators usage in futures, setup fixes

* fix futures market test setup

* fix futures market data tests

* fix next price test setup

* fix system settings tests

* fix integration tests failing to setup markets

* fix market debt calculation during setup

* Deploy SNX/ETH and sUSD/DAI staking rewards on OVM (#1653)

* remove old RewardEscrow from deployment.json for ovm environments (#1658)

* Update kovan-ovm/feeds.json for OCR (#1659)

* verify deployment

* fix market settings tests

* fix futures market tests

* Update feeds.json for kovan ovm with new OCR proxies (#1664)

* Optimism Forking with Hardhat (#1656)


Co-authored-by: jj <jj@og.snxdao.io>

* Remove legacy deployment config from kovan-ovm (#1665)

* Upgrade Gnosis SDK (#1655)

* SIPS 196, 193, 184 - audit fixes, full version (#1661)

* Futures merge 184 (#1672)

* fix breaker merge test

* fix test lints (#1607)

* fix test lints

sometimes the dual tests fail due to race condition built into the tests

in addition, a better event is now being used for monitoring transaction relay status.

Withdrawal tests still don't work because the transaction is not relayed on the L1 side,
I'm guessing because the user has to call `finalize` transaction somehow. Not sure who to talk to if we want to get those tests working.

* fix lints

* uncomment

Co-authored-by: Mark Barrasso <4982406+barrasso@users.noreply.github.com>
Co-authored-by: jj <jj@og.snxdao.io>

* try fix dual itnegration tests

* update migration script to also stage nominations (#1670)

* update migration script to also stage nominations

also the owner can now run migration, instead of the deployer, which is way better for getting stuff done

* fix lints

* re-add legacy onlyDeploy function for older migrations

* add verify step

* use performTransactionalStep

* add signer

* cleanup verify step and additional logging for clarity

* another attempt to fix dual integration tests

* Revert "another attempt to fix dual integration tests"

This reverts commit 64de1c2.

* Revert "try fix dual itnegration tests"

This reverts commit 8d0f088.

* Removing redundant ExchangeRatesWithInversePricing

* Ensuring fork tests do compile (#1679)

* Futures dynamic fee (#1673)

* Sip 185 debt shares (#1601)

* Fix the validate deployment CI run (#1680)

* Removing the redundant owner param from migrations (#1681)

* Collecting Test Metadata in CI (#1683)

* SIP-209 Update feeRateForExchange function signature (#1686)

* Also fix test-coverage in CI

* Updating task-node to properly manage the provider

* Futures size reduction (#1682)

* address preliminary audit comments (#1691)

* Futures pausing (#1692)

* Basic npm audit fix (#1693)

* Updating mainnet-ovm feeds to new chainlink OCR (#1645)

* add moar releases (#1698)

* Fixing ABI anomaly for kovan-ovm for exchangeWithVirtual

* AIP-202 - Upgrade supply schedule to use target ratio inflation amount (#1700)

* Fixing lint

* Updating mainnet-ovm feeds to new chainlink OCR (#1645)

* add moar releases (#1698)

* Polaris release 2.61 to mainnet ovm (#1699)

* SIP-199 sSOL to Optimism
* SCCP-163 OCR feeds on Optimism

* Prepublish step

* 2.61.0

* Fixing ABI anomaly for kovan-ovm for exchangeWithVirtual

* Fixing ABI anomaly for kovan-ovm for exchangeWithVirtual

* 2.61.1

* AIP-202 - Upgrade supply schedule to use target ratio inflation amount (#1700)

* Hamal release v2.62 mainnet (#1706)

* SIP-202 Target Staking Ratio

* Prepublish step

* 2.62.0

* Fixing lint

* deploy new futuresMarkets with dynamic fees to kovan-ovm-futures

* verify

* add ovm etherscan key support (#1703)

* address minor audit issues

* deploy systemStatus

* release exchangeRates

* dual integration test fix attempt

* Futures single market pausing (#1711)

* Futures support multiple markets for same asset (#1713)

* Futures volume source fee methods (#1714)

* update releases json

* revert unrelated contract changes

* fix fork tests (#1717)

* Debtcache import excluded debt entries (#1716)

* SIP-165 Debt Orcale (#1694)

Impl for 165

From a code perspective, this entails:

    FeePool and Issuer are changed to use the chainlink oracle instead of DebtCache and SynthetixDebtShare directly
    FeePool now closes its fee period across networks (using optimism relay call) to allow for synchronized sharing of close parameters between networks
    For testing and initial deployment, a dummy oracles SingleNetworkAggregatorDebtRatio and SingleNetworkAggregatorIssuedSynths are utilized to retrieve debt values for this network, meaning most unit tests can work exactly the same as before.

Notes:

    The SC has indicated that inflation should be divided evenly between networks based on amount of debt shares on each network, so this has been implemented. Also, fees will remain on the network they originate from for the time being
    Dual Integration test was added to verify fee pool closure
    Tests were removed from DebtCache because the functionality is no longer used within the system, but the actual code from solidity was not removed because there is no need to include DebtCache in an update. Doing so would require more migration complexity and it would be better if we could avoid that, so no changes have been made to DebtCache for the time being.

The release process for this SIP is 2 steps:

    First, we will release as usual with the included SingleNetworkAggregators, which will preserve current functionality while enabling for us to start reading from an oracle interface for debt info
    Second, we will use the pdao to change the AddressResolver setting for the two aggregators to be the chainlink provided ones, which will effectively complete the debt synthethsis and enable synth fungibility

* diphda part 1

* diphda part 2

* diphda optimism part 1

* diphda ovm part 2

Co-authored-by: Anton Jurisevic <zyzek@users.noreply.github.com>
Co-authored-by: Liam Zebedeee <liamzebedee@yahoo.com.au>
Co-authored-by: Alejandro Santander <Palebluedot@gmail.com>
Co-authored-by: Synthetix Team <team@synthetix.io>
Co-authored-by: Jackson C <jackosmacko@gmail.com>
Co-authored-by: Justin J. Moses <justinjmoses@gmail.com>
Co-authored-by: justin j. moses <justin@synthetix.io>
Co-authored-by: Yannis <i.stamelakos@gmail.com>
Co-authored-by: Leonardo Massazza <lmassazza+github@gmail.com>
Co-authored-by: Matías Lescano <mjlescano@users.noreply.github.com>
Co-authored-by: David Goldberg <gberg1@users.noreply.github.com>
Co-authored-by: Clément BALESTRAT <clement.balestrat@gmail.com>
Co-authored-by: Mark Barrasso <4982406+barrasso@users.noreply.github.com>
Co-authored-by: Jakub Mucha <jakub.mucha@icloud.com>
Co-authored-by: jj <jj@og.snxdao.io>
Co-authored-by: dbeal <git@dbeal.dev>
Co-authored-by: Lecky <leckylao@gmail.com>
Co-authored-by: Brett Sun <qisheng.brett.sun@gmail.com>
Co-authored-by: Joey <5688912+bachstatter@users.noreply.github.com>
Co-authored-by: Noah Litvin <335975+noahlitvin@users.noreply.github.com>
Co-authored-by: dbeal <git@danb.email>
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.

4 participants