Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.78.3 #11671

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
- [](https://github.com/vegaprotocol/vega/issues/xxx)


## 0.78.3

### 🐛 Fixes

- [11664](https://github.com/vegaprotocol/vega/issues/11664) - Remove unneeded check for market length in `GetPartyStats`.
- [11662](https://github.com/vegaprotocol/vega/issues/11662) - Remove reference to public from query.
- [11665](https://github.com/vegaprotocol/vega/issues/11665) - Delay the final termination of a transfer to the following epoch.
- [11672](https://github.com/vegaprotocol/vega/issues/11672) - Add missing fees in GraphQL bindings.
- [11668](https://github.com/vegaprotocol/vega/issues/11668) - Market depth for `AMM's` when stepping over fair-price adds volume.

## 0.78.2

### 🛠 Improvements
Expand All @@ -33,6 +43,7 @@
- [11650](https://github.com/vegaprotocol/vega/issues/11650) - Add include sub accounts flag to `listPositions`.
- [11641](https://github.com/vegaprotocol/vega/issues/11641) - Panic with pegged orders.
- [11646](https://github.com/vegaprotocol/vega/issues/11646) - Add tier numbers to API.
- [11665](https://github.com/vegaprotocol/vega/issues/11665) - Delay the final termination of a transfer to the following epoch.


## 0.78.1
Expand Down Expand Up @@ -66,6 +77,9 @@
- [11577](https://github.com/vegaprotocol/vega/issues/11577) - Add API for party discounts and rewards.
- [10716](https://github.com/vegaprotocol/vega/issues/10716) - Set Tendermint defaults during init.
- [11624](https://github.com/vegaprotocol/vega/issues/11624) - prevent creation of rewards with no payout, but with high computational cost.
- [11512](https://github.com/vegaprotocol/vega/issues/11512) - Add loss socialisation amounts to funding payment API.
- [11627](https://github.com/vegaprotocol/vega/issues/11627) - Add eligible keys filter to reward transfers.


### 🐛 Fixes

Expand Down
7 changes: 0 additions & 7 deletions core/banking/recurring_transfers.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,6 @@ func (e *Engine) distributeRecurringTransfers(ctx context.Context, newEpoch uint
}

tresps = append(tresps, resps...)

// if we don't have anymore
if v.EndEpoch != nil && *v.EndEpoch == e.currentEpoch {
v.Status = types.TransferStatusDone
transfersDone = append(transfersDone, events.NewRecurringTransferFundsEvent(ctx, v, e.getGameID(v)))
doneIDs = append(doneIDs, v.ID)
}
}

// send events
Expand Down
2 changes: 2 additions & 0 deletions core/banking/recurring_transfers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ func TestMaturation(t *testing.T) {
e.OnEpoch(context.Background(), types.Epoch{Seq: 11, Action: vega.EpochAction_EPOCH_ACTION_END})
e.OnEpoch(context.Background(), types.Epoch{Seq: 12, Action: vega.EpochAction_EPOCH_ACTION_START})
e.OnEpoch(context.Background(), types.Epoch{Seq: 12, Action: vega.EpochAction_EPOCH_ACTION_END})
e.OnEpoch(context.Background(), types.Epoch{Seq: 13, Action: vega.EpochAction_EPOCH_ACTION_START})
e.OnEpoch(context.Background(), types.Epoch{Seq: 13, Action: vega.EpochAction_EPOCH_ACTION_END})

require.Equal(t, 10, len(seenEvts))
stoppedIDs := map[string]struct{}{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Scenario: As a user I can create a recurring transfer that decreases over time w
Then "576380694832d9271682e86fffbbcebc09ca79c259baa5d4d0298e12ecdee303" should have general account balance of "21900" for asset "VEGA"

# end of epoch 5 - the transfer is ended so can't be cancelled
When the network moves ahead "7" blocks
When the network moves ahead "8" blocks
Then "a7c4b181ef9bf5e9029a016f854e4ad471208020fd86187d07f0b420004f06a4" should have general account balance of "962005" for asset "VEGA"
Then "576380694832d9271682e86fffbbcebc09ca79c259baa5d4d0298e12ecdee303" should have general account balance of "25330" for asset "VEGA"

Expand Down Expand Up @@ -174,7 +174,7 @@ Scenario: As a user I can create a recurring transfer that decreases over time w
Then "576380694832d9271682e86fffbbcebc09ca79c259baa5d4d0298e12ecdee303" should have general account balance of "21900" for asset "VEGA"

# end of epoch 5 - the transfer is ended so can't be cancelled
When the network moves ahead "7" blocks
When the network moves ahead "8" blocks
Then "a7c4b181ef9bf5e9029a016f854e4ad471208020fd86187d07f0b420004f06a4" should have general account balance of "956340" for asset "VEGA"
Then "576380694832d9271682e86fffbbcebc09ca79c259baa5d4d0298e12ecdee303" should have general account balance of "25330" for asset "VEGA"

Expand Down
4 changes: 4 additions & 0 deletions datanode/gateway/graphql/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3043,6 +3043,8 @@ func (r *myTradeResolver) BuyerFee(_ context.Context, obj *vegapb.Trade) (*Trade
fee.LiquidityFee = obj.BuyerFee.LiquidityFee
fee.LiquidityFeeReferralDiscount = setIfExists(obj.BuyerFee.LiquidityFeeReferrerDiscount)
fee.LiquidityFeeVolumeDiscount = setIfExists(obj.BuyerFee.LiquidityFeeVolumeDiscount)
fee.TreasuryFee = obj.BuyerFee.TreasuryFee
fee.BuyBackFee = obj.BuyerFee.BuyBackFee
}
return &fee, nil
}
Expand All @@ -3068,6 +3070,8 @@ func (r *myTradeResolver) SellerFee(_ context.Context, obj *vegapb.Trade) (*Trad
fee.LiquidityFee = obj.SellerFee.LiquidityFee
fee.LiquidityFeeReferralDiscount = setIfExists(obj.SellerFee.LiquidityFeeReferrerDiscount)
fee.LiquidityFeeVolumeDiscount = setIfExists(obj.SellerFee.LiquidityFeeVolumeDiscount)
fee.TreasuryFee = obj.SellerFee.TreasuryFee
fee.BuyBackFee = obj.SellerFee.BuyBackFee
}

return &fee, nil
Expand Down
26 changes: 20 additions & 6 deletions datanode/service/market_depth_amm.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ func (m *MarketDepth) expandByLevels(pool entities.AMMPool, levels []*level, pri

estimated := []bool{}
orders := []*types.Order{}

extraVolume := int64(0)
for i := range levels {
if i == len(levels)-1 {
break
Expand Down Expand Up @@ -296,20 +298,32 @@ func (m *MarketDepth) expandByLevels(pool entities.AMMPool, levels []*level, pri
side = types.SideSell
retPrice = level2.price

// if we've stepped over the pool's position we need to split the step
// if we've stepped over the pool's position we need to split the volume and add it to the outer levels
if v1.GreaterThan(ammDefn.position) {
volume := v1.Sub(ammDefn.position).Abs().IntPart()
o := m.makeOrder(level1.price, ammDefn.partyID, uint64(volume), types.SideBuy)
orders = append(orders, o)
estimated = append(estimated, level1.estimated)

// now set v1 ready for the second half of this split
v1 = ammDefn.position
// we want to add the volume to the previous order, because thats the price in marketDP when rounded away
// from the fair-price
if len(orders) != 0 {
o := orders[len(orders)-1]
o.Size += uint64(volume)
o.Remaining += uint64(volume)
}

// we need to add this volume to the price level we step to next
extraVolume = ammDefn.position.Sub(v2).Abs().IntPart()
continue
}
}
// calculate the volume
volume := v1.Sub(v2).Abs().IntPart()

// this is extra volume from when we stepped over the AMM's fair-price
if extraVolume != 0 {
volume += extraVolume
extraVolume = 0
}

orders = append(
orders,
m.makeOrder(retPrice, ammDefn.partyID, uint64(volume), side),
Expand Down
79 changes: 61 additions & 18 deletions datanode/service/market_depth_amm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func Test_0015_NP_OBES_002(t *testing.T) {
marketID := vgcrypto.RandomHash()

mds.orders.EXPECT().GetLiveOrders(gomock.Any()).Return([]entities.Order{}, nil)
ensureDecimalPlaces(t, mds)
ensureDecimalPlaces(t, mds, 1, 1)
mds.pos.EXPECT().GetByMarketAndParty(gomock.Any(), gomock.Any(), gomock.Any()).Return(entities.Position{OpenVolume: 0}, nil)

// mid-price is 100
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestAMMMarketDepth(t *testing.T) {
marketID := vgcrypto.RandomHash()

ensureLiveOrders(t, mds, marketID)
ensureDecimalPlaces(t, mds)
ensureDecimalPlaces(t, mds, 1, 1)
mds.pos.EXPECT().GetByMarketAndParty(gomock.Any(), gomock.Any(), gomock.Any()).Return(entities.Position{OpenVolume: 0}, nil)
mds.marketData.EXPECT().GetMarketDataByID(gomock.Any(), gomock.Any()).Times(1).Return(entities.MarketData{MidPrice: num.DecimalFromInt64(2000)}, nil)

Expand Down Expand Up @@ -180,7 +180,7 @@ func TestAMMMarketDepth(t *testing.T) {
assert.Equal(t, 120, int(mds.service.GetAMMVolume(marketID, false)))
assert.Equal(t, 260, int(mds.service.GetTotalVolume(marketID)))

assert.Equal(t, "1996", mds.service.GetBestBidPrice(marketID).String())
assert.Equal(t, "1995", mds.service.GetBestBidPrice(marketID).String())
assert.Equal(t, "1998", mds.service.GetBestAskPrice(marketID).String())

// now the AMM is updated so that its definition has changed, namely that its curve when short is removed
Expand All @@ -194,7 +194,7 @@ func TestAMMMarketDepth(t *testing.T) {
assert.Equal(t, 65, int(mds.service.GetAMMVolume(marketID, true)))
assert.Equal(t, 60, int(mds.service.GetAMMVolume(marketID, false)))
assert.Equal(t, 145, int(mds.service.GetTotalVolume(marketID)))
assert.Equal(t, "1996", mds.service.GetBestBidPrice(marketID).String())
assert.Equal(t, "1995", mds.service.GetBestBidPrice(marketID).String())
assert.Equal(t, "1998", mds.service.GetBestAskPrice(marketID).String())

// and there should definitely be no volume at 2001
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestAMMInitialiseNoAMM(t *testing.T) {
newMarket := vgcrypto.RandomHash()
pool := getAMMDefinition(t, newMarket)

ensureDecimalPlaces(t, mds)
ensureDecimalPlaces(t, mds, 1, 1)
mds.pos.EXPECT().GetByMarketAndParty(gomock.Any(), gomock.Any(), gomock.Any()).Return(entities.Position{OpenVolume: 0}, nil)
mds.marketData.EXPECT().GetMarketDataByID(gomock.Any(), gomock.Any()).Times(1).Return(entities.MarketData{MidPrice: num.DecimalFromInt64(2000)}, nil)
mds.service.OnAMMUpdate(pool, time.Now(), 1000)
Expand All @@ -252,7 +252,7 @@ func TestAMMStepOverFairPrice(t *testing.T) {

marketID := vgcrypto.RandomHash()
ensureLiveOrders(t, mds, marketID)
ensureDecimalPlaces(t, mds)
ensureDecimalPlaces(t, mds, 1, 1)
mds.pos.EXPECT().GetByMarketAndParty(gomock.Any(), gomock.Any(), gomock.Any()).Return(entities.Position{OpenVolume: 0}, nil)
mds.marketData.EXPECT().GetMarketDataByID(gomock.Any(), gomock.Any()).Times(1).Return(entities.MarketData{MidPrice: num.DecimalFromInt64(2000)}, nil)

Expand Down Expand Up @@ -280,11 +280,12 @@ func TestAMMStepOverFairPrice(t *testing.T) {
37,
)

assert.Equal(t, "1999", mds.service.GetBestBidPrice(marketID).String())
assert.Equal(t, "2000", mds.service.GetBestAskPrice(marketID).String())
assert.Equal(t, 2, int(mds.service.GetVolumeAtPrice(marketID, types.SideBuy, 1999)))
assert.Equal(t, 1, int(mds.service.GetVolumeAtPrice(marketID, types.SideSell, 2000)))
assert.Equal(t, 3, int(mds.service.GetVolumeAtPrice(marketID, types.SideSell, 2001)))
assert.Equal(t, "1998", mds.service.GetBestBidPrice(marketID).String())
assert.Equal(t, "2001", mds.service.GetBestAskPrice(marketID).String())
assert.Equal(t, 0, int(mds.service.GetVolumeAtPrice(marketID, types.SideBuy, 1999)))
assert.Equal(t, 0, int(mds.service.GetVolumeAtPrice(marketID, types.SideSell, 2000)))
assert.Equal(t, 5, int(mds.service.GetVolumeAtPrice(marketID, types.SideBuy, 1998)))
assert.Equal(t, 4, int(mds.service.GetVolumeAtPrice(marketID, types.SideSell, 2001)))
}

func TestAMMSmallBounds(t *testing.T) {
Expand All @@ -300,7 +301,7 @@ func TestAMMSmallBounds(t *testing.T) {

marketID := vgcrypto.RandomHash()
ensureLiveOrders(t, mds, marketID)
ensureDecimalPlaces(t, mds)
ensureDecimalPlaces(t, mds, 1, 1)
mds.pos.EXPECT().GetByMarketAndParty(gomock.Any(), gomock.Any(), gomock.Any()).Return(entities.Position{OpenVolume: 0}, nil)
mds.marketData.EXPECT().GetMarketDataByID(gomock.Any(), gomock.Any()).Times(1).Return(entities.MarketData{MidPrice: num.DecimalFromInt64(2000)}, nil)

Expand Down Expand Up @@ -331,7 +332,7 @@ func TestEstimatedStepOverAMMBound(t *testing.T) {

marketID := vgcrypto.RandomHash()
ensureLiveOrders(t, mds, marketID)
ensureDecimalPlaces(t, mds)
ensureDecimalPlaces(t, mds, 1, 1)
mds.pos.EXPECT().GetByMarketAndParty(gomock.Any(), gomock.Any(), gomock.Any()).Return(entities.Position{OpenVolume: 0}, nil)
mds.marketData.EXPECT().GetMarketDataByID(gomock.Any(), gomock.Any()).Times(1).Return(entities.MarketData{MidPrice: num.DecimalFromInt64(2000)}, nil)

Expand Down Expand Up @@ -360,7 +361,7 @@ func TestExpansionMuchBiggerThanAMMs(t *testing.T) {
marketID := vgcrypto.RandomHash()

ensureLiveOrders(t, mds, marketID)
ensureDecimalPlaces(t, mds)
ensureDecimalPlaces(t, mds, 1, 1)
mds.pos.EXPECT().GetByMarketAndParty(gomock.Any(), gomock.Any(), gomock.Any()).Return(entities.Position{OpenVolume: 0}, nil)
mds.marketData.EXPECT().GetMarketDataByID(gomock.Any(), gomock.Any()).Times(1).Return(entities.MarketData{MidPrice: num.DecimalFromInt64(2000)}, nil)

Expand All @@ -386,7 +387,7 @@ func TestMidPriceMove(t *testing.T) {
marketID := vgcrypto.RandomHash()

ensureLiveOrders(t, mds, marketID)
ensureDecimalPlaces(t, mds)
ensureDecimalPlaces(t, mds, 1, 1)
mds.pos.EXPECT().GetByMarketAndParty(gomock.Any(), gomock.Any(), gomock.Any()).Return(entities.Position{OpenVolume: 0}, nil)
mds.marketData.EXPECT().GetMarketDataByID(gomock.Any(), gomock.Any()).Times(1).Return(entities.MarketData{MidPrice: num.DecimalFromInt64(2000)}, nil)

Expand Down Expand Up @@ -421,6 +422,29 @@ func TestMidPriceMove(t *testing.T) {
assert.Equal(t, "3000", mds.service.GetBestAskPrice(marketID).String()) // this is an actual order volume not AMM volume
}

func TestFairgroundAMM(t *testing.T) {
ctx := context.Background()

mds := getService(t)
defer mds.ctrl.Finish()

marketID := vgcrypto.RandomHash()

mds.orders.EXPECT().GetLiveOrders(gomock.Any()).Return(nil, nil)
ensureDecimalPlaces(t, mds, 9, 5)
mds.pos.EXPECT().GetByMarketAndParty(gomock.Any(), gomock.Any(), gomock.Any()).Return(entities.Position{OpenVolume: -69005905}, nil)
mds.marketData.EXPECT().GetMarketDataByID(gomock.Any(), gomock.Any()).Times(1).Return(entities.MarketData{MidPrice: num.DecimalFromInt64(12955)}, nil)

pool := getAMMDefinitionTestnet(t, marketID)
mds.amm.EXPECT().ListActive(gomock.Any()).Return([]entities.AMMPool{pool}, nil).Times(1)
mds.service.Initialise(ctx)

// AMM's fair price is 129543034, so +/- one each side is 129533034, 129553034
// the we round *away* from the fair price and get:
assert.Equal(t, "12953", mds.service.GetBestBidPrice(marketID).String())
assert.Equal(t, "12956", mds.service.GetBestAskPrice(marketID).String())
}

func ensureLiveOrders(t *testing.T, mds *MDS, marketID string) {
t.Helper()
mds.orders.EXPECT().GetLiveOrders(gomock.Any()).Return([]entities.Order{
Expand Down Expand Up @@ -485,6 +509,25 @@ func getAMMDefinitionMid100(t *testing.T, marketID string) entities.AMMPool {
}
}

func getAMMDefinitionTestnet(t *testing.T, marketID string) entities.AMMPool {
t.Helper()

// position -69005905

return entities.AMMPool{
PartyID: entities.PartyID(vgcrypto.RandomHash()),
AmmPartyID: entities.PartyID(vgcrypto.RandomHash()),
MarketID: entities.MarketID(marketID),
ParametersLowerBound: ptr.From(num.DecimalFromInt64(11403)),
LowerVirtualLiquidity: num.DecimalFromFloat(32934372037780.849503179454583540865465761125),
LowerTheoreticalPosition: num.DecimalFromFloat(158269985.323671339473934),
ParametersBase: num.DecimalFromInt64(12670),
ParametersUpperBound: ptr.From(num.DecimalFromInt64(13937)),
UpperVirtualLiquidity: num.DecimalFromFloat(70393727154384.2551793351731482811200266360637),
UpperTheoreticalPosition: num.DecimalFromFloat(291036775.097792633711267),
}
}

func ensureAMMs(t *testing.T, mds *MDS, marketID string) entities.AMMPool {
t.Helper()

Expand All @@ -493,7 +536,7 @@ func ensureAMMs(t *testing.T, mds *MDS, marketID string) entities.AMMPool {
return pool
}

func ensureDecimalPlaces(t *testing.T, mds *MDS) {
func ensureDecimalPlaces(t *testing.T, mds *MDS, adp, mdp int) {
t.Helper()

market := entities.Market{
Expand All @@ -506,13 +549,13 @@ func ensureDecimalPlaces(t *testing.T, mds *MDS) {
},
},
},
DecimalPlaces: 1,
DecimalPlaces: mdp,
TickSize: ptr.From(num.DecimalOne()),
}
mds.markets.EXPECT().GetByID(gomock.Any(), gomock.Any()).Return(market, nil)

asset := entities.Asset{
Decimals: 1,
Decimals: adp,
}
mds.assets.EXPECT().GetByID(gomock.Any(), gomock.Any()).Return(asset, nil)
}
5 changes: 0 additions & 5 deletions datanode/service/party_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package service

import (
"context"
"fmt"

"code.vegaprotocol.io/vega/datanode/entities"
"code.vegaprotocol.io/vega/libs/num"
Expand Down Expand Up @@ -101,10 +100,6 @@ func NewPartyStatsService(epoch EpochStore, ref ReferralSetStore, vds VDSStore,
}

func (s *PSvc) GetPartyStats(ctx context.Context, partyID string, markets []string) (*v2.GetPartyDiscountStatsResponse, error) {
// ensure the arguments we received make sense:
if len(markets) == 0 {
return nil, fmt.Errorf("required to provide at least one market ID")
}
// first up, last epoch to get the stats:
epoch, err := s.epoch.GetCurrent(ctx)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion datanode/sqlstore/volume_discount_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *VolumeDiscountStats) Add(ctx context.Context, stats *entities.VolumeDis
}

func (s *VolumeDiscountStats) LatestStats(ctx context.Context, partyID string) (entities.VolumeDiscountStats, error) {
query := `SELECT * FROM public.volume_discount_stats WHERE
query := `SELECT * FROM volume_discount_stats WHERE
at_epoch = (SELECT id - 1 from current_epochs ORDER BY id DESC, vega_time DESC FETCH FIRST ROW ONLY) AND
EXISTS (SELECT TRUE FROM jsonb_array_elements(parties_volume_discount_stats) ps WHERE ps->>'party_id' = '$1')`
ent := []entities.VolumeDiscountStats{}
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.78.2";
version: "v0.78.3";
}
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.78.2";
version: "v0.78.3";
}
schemes: [
HTTP,
Expand Down
Loading
Loading