Skip to content

Commit

Permalink
Merge pull request #11495 from vegaprotocol/11493-amend-to-empty-curves
Browse files Browse the repository at this point in the history
fix: reject AMM amendment to a one-sided AMM if its position is alrea…
  • Loading branch information
wwestgarth authored Jul 24, 2024
2 parents 6691a3d + 5565846 commit 20cc9dc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/execution/amm/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package amm

import (
"errors"
"fmt"

"code.vegaprotocol.io/vega/core/idgeneration"
Expand Down Expand Up @@ -324,6 +325,16 @@ func (p *Pool) Update(
parameters = amend.Parameters
}

// if an AMM is amended so that it cannot be long (i.e it has no lower curve) but the existing AMM
// is already long then we cannot make the change since its fair-price will be undefined.
if parameters.LowerBound == nil && p.getPosition() > 0 {
return nil, errors.New("cannot remove lower bound when AMM is long")
}

if parameters.UpperBound == nil && p.getPosition() < 0 {
return nil, errors.New("cannot remove upper bound when AMM is short")
}

updated := &Pool{
log: p.log,
ID: p.ID,
Expand Down
24 changes: 24 additions & 0 deletions core/integration/features/amm/0090-VAMM-basic.feature
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,29 @@ Feature: vAMM rebasing when created or amended
| party | market id | method | error |
| party1 | ETH/MAR22 | METHOD_IMMEDIATE | trading not allowed |


@VAMM
Scenario: Cannot amend AMM to have only one side if its current position does not support it

When the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif | reference |
| party1 | ETH/MAR22 | sell | 1 | 99 | 1 | TYPE_LIMIT | TIF_GTC | |


Then the parties amend the following AMM:
| party | market id | amount | slippage | base | upper bound | proposed fee | error |
| vamm1 | ETH/MAR22 | 100000 | 0.05 | 100 | 105 | 0.03 | cannot remove lower bound when AMM is long |


When the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif | reference |
| party1 | ETH/MAR22 | buy | 2 | 200 | 1 | TYPE_LIMIT | TIF_GTC | |

Then the parties amend the following AMM:
| party | market id | amount | slippage | base | lower bound | proposed fee | error |
| vamm1 | ETH/MAR22 | 100000 | 0.05 | 100 | 95 | 0.03 | cannot remove upper bound when AMM is short |





0 comments on commit 20cc9dc

Please sign in to comment.