Skip to content

Commit

Permalink
fix: an AMM waiting for a data source cannot be set to reduce only
Browse files Browse the repository at this point in the history
  • Loading branch information
wwestgarth committed Oct 25, 2024
1 parent a50750c commit fe9f4ef
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
6 changes: 6 additions & 0 deletions core/execution/amm/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
ErrCommitmentTooLow = errors.New("commitment amount too low")
ErrRebaseOrderDidNotTrade = errors.New("rebase-order did not trade")
ErrRebaseTargetOutsideBounds = errors.New("rebase target outside bounds")
ErrCannotCancelPendingAMM = errors.New("pending AMM with a position cannot be cancelled with reduce-only method")
)

const (
Expand Down Expand Up @@ -800,6 +801,11 @@ func (e *Engine) CancelAMM(
}

if cancel.Method == types.AMMCancellationMethodReduceOnly {
// a pending pool has no curves until a data-source sets its base, so cannot be set in reduce-only mode
if pool.IsPending() {
return nil, ErrCannotCancelPendingAMM
}

// pool will now only accept trades that will reduce its position
pool.status = types.AMMPoolStatusReduceOnly
e.sendUpdate(ctx, pool)
Expand Down
43 changes: 42 additions & 1 deletion core/integration/features/amm/0090-VAMM-oracle-base.feature
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,45 @@ Feature: vAMM with oracle driven base price
# base price update only happened because the slippage was increased in the amend that set the new oracle value
Then the AMM pool status should be:
| party | market id | amount | status | base | lower bound | upper bound |
| vamm1 | ETH/MAR22 | 100000 | STATUS_ACTIVE | 115 | 80 | 120 |
| vamm1 | ETH/MAR22 | 100000 | STATUS_ACTIVE | 115 | 80 | 120 |


@VAMM3
Scenario: 0090-VAMM-043 AMM amended into pending AMM cannot be set into reduce only
Then the parties submit the following AMM:
| party | market id | amount | slippage | base | lower bound | upper bound | proposed fee |
| vamm1 | ETH/MAR22 | 100000 | 0.01 | 100 | 80 | 120 | 0.03 |
Then the AMM pool status should be:
| party | market id | amount | status | base | lower bound | upper bound |
| vamm1 | ETH/MAR22 | 100000 | STATUS_ACTIVE | 100 | 80 | 120 |


# give it a position
When the parties place the following orders:
| party | market id | side | volume | price | resulting trades | type | tif | reference |
| party1 | ETH/MAR22 | sell | 10 | 50 | 1 | TYPE_LIMIT | TIF_GTC | |

# the base price is
Then the parties amend the following AMM:
| party | market id | amount | slippage | base | lower bound | upper bound | proposed fee | data source id |
| vamm1 | ETH/MAR22 | 100000 | 0.05 | 0 | 200 | 300 | 0.03 | 1234 |
Then the AMM pool status should be:
| party | market id | amount | status | base | lower bound | upper bound |
| vamm1 | ETH/MAR22 | 100000 | STATUS_PENDING | 0 | 200 | 300 |



# try to cancel with reduce only
Then the parties cancel the following AMM:
| party | market id | method | error |
| vamm1 | ETH/MAR22 | METHOD_REDUCE_ONLY | pending AMM with a position cannot be cancelled with reduce-only method |

# try to cancel with immediate
Then the parties cancel the following AMM:
| party | market id | method |
| vamm1 | ETH/MAR22 | METHOD_IMMEDIATE |

# base price update only happened because the slippage was increased in the amend that set the new oracle value
Then the AMM pool status should be:
| party | market id | amount | status | base | lower bound | upper bound |
| vamm1 | ETH/MAR22 | 100000 | STATUS_CANCELLED | 0 | 200 | 300 |

0 comments on commit fe9f4ef

Please sign in to comment.