Skip to content

Commit

Permalink
chore: merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ze97286 committed Jul 24, 2024
2 parents 2d72119 + 227afa8 commit 8afe20a
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 14 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
- [](https://github.com/vegaprotocol/vega/issues/xxx)


## 0.77.2

### 🐛 Fixes

- [11481](https://github.com/vegaprotocol/vega/issues/11481) - Fix margin check for cross margin market orders.
- [11474](https://github.com/vegaprotocol/vega/issues/11474) - Fail `checkTx` downstream for delayed transactions so they don't get included in more than one block.

## 0.77.1

### 🛠 Improvements
Expand All @@ -31,7 +38,7 @@

- [11453](https://github.com/vegaprotocol/vega/issues/11453) - Fix margin for fully collateralised markets.
- [11462](https://github.com/vegaprotocol/vega/issues/11462) - Update the time weighted notional when publishing live game scores.
- [11474](https://github.com/vegaprotocol/vega/issues/11474) - Fail `checkTx` downstream for delayed transactions so they don't get included in more than one block.
- [11474](https://github.com/vegaprotocol/vega/issues/11474) - Fail `checkTx` downstream for delayed transactions so they don't get included in more than one block.
- [11481](https://github.com/vegaprotocol/vega/issues/11481) - Fix margin check for cross margin market orders.

## 0.77.0
Expand Down
4 changes: 2 additions & 2 deletions core/execution/amm/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func (e *Engine) BestPricesAndVolumes() (*num.Uint, uint64, *num.Uint, uint64) {
fp := pool.BestPrice(nil)

// get the volume on the buy side by simulating an incoming sell order
bid := num.UintZero().Sub(fp, pool.oneTick)
bid := num.Max(pool.lower.low, num.UintZero().Sub(fp, pool.oneTick))
volume := pool.TradableVolumeInRange(types.SideSell, fp.Clone(), bid)

if volume != 0 {
Expand All @@ -341,7 +341,7 @@ func (e *Engine) BestPricesAndVolumes() (*num.Uint, uint64, *num.Uint, uint64) {
}

// get the volume on the sell side by simulating an incoming buy order
ask := num.UintZero().Add(fp, pool.oneTick)
ask := num.Min(pool.upper.high, num.UintZero().Add(fp, pool.oneTick))
volume = pool.TradableVolumeInRange(types.SideBuy, fp.Clone(), ask)
if volume != 0 {
if bestAsk == nil || ask.LT(bestAsk) {
Expand Down
52 changes: 50 additions & 2 deletions core/execution/amm/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,49 @@ func testBestPricesAndVolume(t *testing.T) {
assert.Equal(t, avolume, avAt)
}

func TestBestPricesAndVolumeNearBound(t *testing.T) {
tst := getTestEngineWithFactors(t, num.DecimalFromInt64(100), num.DecimalFromFloat(10))

// create three pools
party, subAccount := getParty(t, tst)
submit := getPoolSubmission(t, party, tst.marketID)

expectSubaccountCreation(t, tst, party, subAccount)
whenAMMIsSubmitted(t, tst, submit)

tst.pos.EXPECT().GetPositionsByParty(gomock.Any()).Times(5).Return(
[]events.MarketPosition{&marketPosition{size: 0, averageEntry: num.NewUint(0)}},
)

bid, bvolume, ask, avolume := tst.engine.BestPricesAndVolumes()
assert.Equal(t, "199900", bid.String())
assert.Equal(t, "200100", ask.String())
assert.Equal(t, 1250, int(bvolume))
assert.Equal(t, 1192, int(avolume))

// lets move its position so that the fair price is within one tick of the AMMs upper boundary
tst.pos.EXPECT().GetPositionsByParty(gomock.Any()).Times(5).Return(
[]events.MarketPosition{&marketPosition{size: -222000, averageEntry: num.NewUint(0)}},
)

bid, bvolume, ask, avolume = tst.engine.BestPricesAndVolumes()
assert.Equal(t, "219890", bid.String())
assert.Equal(t, "220000", ask.String()) // make sure we are capped to the boundary and not 220090
assert.Equal(t, 1034, int(bvolume))
assert.Equal(t, 103, int(avolume))

// lets move its position so that the fair price is within one tick of the AMMs upper boundary
tst.pos.EXPECT().GetPositionsByParty(gomock.Any()).Times(5).Return(
[]events.MarketPosition{&marketPosition{size: 270400, averageEntry: num.NewUint(0)}},
)

bid, bvolume, ask, avolume = tst.engine.BestPricesAndVolumes()
assert.Equal(t, "180000", bid.String()) // make sure we are capped to the boundary and not 179904
assert.Equal(t, "180104", ask.String())
assert.Equal(t, 58, int(bvolume))
assert.Equal(t, 1463, int(avolume))
}

func testClosingReduceOnlyPool(t *testing.T) {
ctx := context.Background()
tst := getTestEngine(t)
Expand Down Expand Up @@ -709,7 +752,7 @@ type tstEngine struct {
assetID string
}

func getTestEngine(t *testing.T) *tstEngine {
func getTestEngineWithFactors(t *testing.T, priceFactor, positionFactor num.Decimal) *tstEngine {
t.Helper()
ctrl := gomock.NewController(t)
col := mocks.NewMockCollateral(ctrl)
Expand All @@ -730,7 +773,7 @@ func getTestEngine(t *testing.T) *tstEngine {
parties := cmocks.NewMockParties(ctrl)
parties.EXPECT().AssignDeriveKey(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()

eng := New(logging.NewTestLogger(), broker, col, marketID, assetID, pos, num.DecimalOne(), num.DecimalOne(), mat, parties)
eng := New(logging.NewTestLogger(), broker, col, marketID, assetID, pos, priceFactor, positionFactor, mat, parties)

// do an ontick to initialise the idgen
ctx := vgcontext.WithTraceID(context.Background(), vgcrypto.RandomHash())
Expand All @@ -748,6 +791,11 @@ func getTestEngine(t *testing.T) *tstEngine {
}
}

func getTestEngine(t *testing.T) *tstEngine {
t.Helper()
return getTestEngineWithFactors(t, num.DecimalOne(), num.DecimalOne())
}

func getAccount(balance uint64) *types.Account {
return &types.Account{
Balance: num.NewUint(balance),
Expand Down
2 changes: 1 addition & 1 deletion protos/blockexplorer/api/v1/blockexplorer.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protos/data-node/api/v2/trading_data.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protos/sources/blockexplorer/api/v1/blockexplorer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ option go_package = "code.vegaprotocol.io/vega/protos/blockexplorer/api/v1";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
info: {
title: "Vega block explorer APIs";
version: "v0.77.1";
version: "v0.77.2";
}
schemes: [
HTTP,
Expand Down
2 changes: 1 addition & 1 deletion protos/sources/data-node/api/v2/trading_data.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ option go_package = "code.vegaprotocol.io/vega/protos/data-node/api/v2";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
info: {
title: "Vega data node APIs";
version: "v0.77.1";
version: "v0.77.2";
}
schemes: [
HTTP,
Expand Down
2 changes: 1 addition & 1 deletion protos/sources/vega/api/v1/core.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ option go_package = "code.vegaprotocol.io/vega/protos/vega/api/v1";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
info: {
title: "Vega core APIs";
version: "v0.77.1";
version: "v0.77.2";
}
schemes: [
HTTP,
Expand Down
2 changes: 1 addition & 1 deletion protos/sources/vega/api/v1/corestate.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ option go_package = "code.vegaprotocol.io/vega/protos/vega/api/v1";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
info: {
title: "Vega core state APIs";
version: "v0.77.1";
version: "v0.77.2";
}
schemes: [
HTTP,
Expand Down
2 changes: 1 addition & 1 deletion protos/vega/api/v1/core.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protos/vega/api/v1/corestate.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

var (
cliVersionHash = ""
cliVersion = "v0.77.1"
cliVersion = "v0.77.2"
)

func init() {
Expand Down

0 comments on commit 8afe20a

Please sign in to comment.