Skip to content

Commit

Permalink
Merge branch 'develop' into fix-retrograde-amm-volume
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyletang authored Sep 3, 2024
2 parents fd45567 + 1368c15 commit a62dfac
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- [11521](https://github.com/vegaprotocol/vega/issues/11521) - Restore `AMM` position factor when loading from a snapshot.
- [11526](https://github.com/vegaprotocol/vega/issues/11526) - `EstimateAMMBounds` now respects the market's decimal places.
- [11486](https://github.com/vegaprotocol/vega/issues/11486) - `AMMs` can now be submitted on markets with more decimal places than asset decimal places.
- [11635](https://github.com/vegaprotocol/vega/issues/11635) - Handle expansion of one sided `AMMs` that reduce to point expansion when calculating order book shape.
- [11561](https://github.com/vegaprotocol/vega/issues/11561) - Failing amends on `AMMs` now restore original properly.
- [11583](https://github.com/vegaprotocol/vega/issues/11583) - Remove `AMMs` entirely from engine when market closes.
- [11568](https://github.com/vegaprotocol/vega/issues/11568) - order book shape on closing `AMM` no longer panics.
Expand Down
10 changes: 6 additions & 4 deletions core/execution/amm/shape.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,15 @@ func (sm *shapeMaker) adjustRegion() bool {
return false
}

if sm.from.EQ(sm.to) && sm.from.EQ(sm.fairPrice) {
return false
}

// cap the range to the pool's bounds, there will be no orders outside of this
from := num.Max(sm.from, lower)
to := num.Min(sm.to, upper)

// expansion is a point region *at* fair-price, there are no orders
if from.EQ(to) && from.EQ(sm.fairPrice) {
return false
}

switch {
case sm.from.GT(sm.fairPrice):
// if we are expanding entirely in the sell range to calculate the order at price `from`
Expand Down
34 changes: 34 additions & 0 deletions core/execution/amm/shape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestOrderbookShape(t *testing.T) {
t.Run("test orderbook shape boundary order when approx", testOrderbookShapeBoundaryOrder)
t.Run("test orderbook shape region not divisible by tick", testOrderbookSubTick)
t.Run("test orderbook shape closing pool close to base", testClosingCloseToBase)
t.Run("test orderbook shape point expansion at fair price", testPointExpansionAtFairPrice)
}

func testOrderbookShapeZeroPosition(t *testing.T) {
Expand Down Expand Up @@ -416,3 +417,36 @@ func testClosingCloseToBase(t *testing.T) {
assert.Equal(t, 0, len(buys))
assert.Equal(t, 0, len(sells))
}

func testPointExpansionAtFairPrice(t *testing.T) {
p := newTestPoolWithRanges(t, num.NewUint(7), num.NewUint(10), num.NewUint(13))
defer p.ctrl.Finish()

base := p.submission.Parameters.Base

// range [10, 10] fair price is 10, no orders
ensurePositionN(t, p.pos, 0, num.UintZero(), 2)
buys, sells := p.pool.OrderbookShape(base, base, nil)
assert.Equal(t, 0, len(buys))
assert.Equal(t, 0, len(sells))

// now try with a one sided curve where the input range shrinks to a point-expansion
p = newTestPoolWithRanges(t, num.NewUint(7), num.NewUint(10), nil)
defer p.ctrl.Finish()

// range [10, 1000] but sell curve is empty so effective range is [10, 10] at fair-price
ensurePositionN(t, p.pos, 0, num.UintZero(), 2)
buys, sells = p.pool.OrderbookShape(base, num.NewUint(1000), nil)
assert.Equal(t, 0, len(buys))
assert.Equal(t, 0, len(sells))

// now try with a one sided curve where the input range shrinks to a point-expansion
p = newTestPoolWithRanges(t, nil, num.NewUint(10), num.NewUint(13))
defer p.ctrl.Finish()

// range [1, 10] but buy curve is empty so effective range is [10, 10] at fair-price
ensurePositionN(t, p.pos, 0, num.UintZero(), 2)
buys, sells = p.pool.OrderbookShape(num.NewUint(1), base, nil)
assert.Equal(t, 0, len(buys))
assert.Equal(t, 0, len(sells))
}

0 comments on commit a62dfac

Please sign in to comment.