Synthetixio / issues

0 stars 3 forks source link

[TASK] Next price confirmation #370

Closed liamzebedee closed 2 years ago

liamzebedee commented 2 years ago

Context

artdgn commented 2 years ago

Issues with previous version of mechanism:

Proposed mechanism

 submitNextPriceOrder(...)
    - if previous order exists reverts
    - stores the order data + funding index
    - deducts holding-fee from margin

- cancelNextPriceOrder():
    - sends holding-fee to fee-pool
    - removes order

- executeStoredOrder(address account)
    - can be triggered by anyone, at any time after next price(reverts if too soon)
    - in revertless low level call to itself (internal external low level call) executes modifyPosition, remember if call was success
    - remove stored order
    - pay holding fee: 
        - if account is sender: 
            - if call was success - returns fee to margin
            - if call was failure - pay to fee-pool
        - otherwise transfer holding fee to msg.sender (keeper)
artdgn commented 2 years ago

A simpler mechanism after a discussion:

    - submitNextPriceOrder(...)
        - if previous order exists reverts
        - stores the order data + funding index
        - check order is possible with current price (to prevent submitting known bad orders)
        - deduct holding-fee and keeper-fee from margin

    - executeStoredOrder(address account)
        - can be triggered by anyone, at any time after next price(reverts if too soon)
        - in revertless low level call to itself (internal external low level call) executes modifyPosition, remember if call was success
        - remove stored order
        - pay fees (holding-fee and keeper-fee): 
            - call was success - holding-fee back to margin, otherwise to fee-pool
            - sender is original account - keeper-fee back to margin, otherwise to msg.sender

    parameters: 
        holdingFee - can be zero initially if no exploit scenarios are found for free cancellation
        keeperFee - can be equal to minLiquidationFee (20 sUSD)
        nextPriceFee - 5 bp instead of regular spot fee (30 bps)

Main points of discussion:

Next steps

artdgn commented 2 years ago

Mechanism was updated again (following another exploit scenario).

Follow ups for another PR / task:

artdgn commented 2 years ago

PR: https://github.com/Synthetixio/synthetix/pull/1609