🚨 Emergency Close 🚨

How to close your position in an emergency

If you are unable to close your position for any reason, you can close it via contract interaction. It is highly recommended to practice this method before trading in size, in order to have it as a backup trading method.

Note: You will need xDAI to pay for the transaction.

  1. Get the AMM address for the relevant market at https://metadata.perp.exchange/production.json​https://metadata.perp.exchange/production.json Example (ETH):

    ​​

  2. Go to the Perpetual Protocol clearinghouse contract on Blockscout (verify the address in the metadata json linked in step 1)

    ​​

  3. Go to the Write Proxy tab

    ​​

  4. Connect Metamask

    ​​

  5. In 3. closePosition enter the AMM address from step 1

    ​​

  6. Calculate _quoteAssetAmountLimit - this limits the amount of slippage you will accept. In a severe emergency, consider entering 0 (allow 100% slippage).

    1. Take the USDC value of your margin and multiply by 1 - % of slippage. E.g. to allow up to 0.5% slippage with $1000 worth of margin, 1000 * (1-0.5) = 995.

    2. Multiply the result by 10^18. E.g. 995 * 10^18 = 995000000000000000000

    3. Enter this amount for _quoteAssetAmountLimit

  7. Write to the contract to close the position.

    ​ Optional steps

  8. Choose an 'emergency' level gas price - you can see gas prices for recent successful transactions by clicking transaction times shown in the history on perp.exchange. Alternatively, enter a very high number keeping in mind that on xDai, 1000 gwei is $1.00, 2500 gwei is $2.50, etc.

  9. Set a leaner gas limit - the default is 3.8m which is very conservative (ie. very high). Nodes may process this later, favoring smaller transactions. Try lower gas limits, e.g. 2m, 1.5m, etc.

  10. Also practice with addMargin, openPosition etc.

    Note that _side refers to short (0) and long (1), and _baseAssetAmountLimit is the minimum position size (to control slippage - value must be multiplied by 10^18).