Skip to content

Commit

Permalink
Merge pull request #9942 from vegaprotocol/fix/9940
Browse files Browse the repository at this point in the history
fix: truncate fee stats quantume balances down to 6th decimal
  • Loading branch information
jeremyletang authored Oct 31, 2023
2 parents dfddefe + b8a6b7c commit d098780
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

### 🐛 Fixes

- [](https://github.com/vegaprotocol/vega/issues/xxxx) -
- [9941](https://github.com/vegaprotocol/vega/issues/9941) - Add data node mapping for `WasEligible` field in referral set.
- [9940](https://github.com/vegaprotocol/vega/issues/9940) - Truncate fee stats in quantum down to the 6 decimal.


## 0.73.0
Expand Down
12 changes: 6 additions & 6 deletions core/fee/rebate_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (f *FeesStats) ToProto(asset string, assetQuantum num.Decimal) *eventspb.Fe
fs.TotalRewardsReceived = append(fs.TotalRewardsReceived, &eventspb.PartyAmount{
Party: party,
Amount: amount.String(),
QuantumAmount: amount.ToDecimal().Div(assetQuantum).Truncate(2).String(),
QuantumAmount: amount.ToDecimal().Div(assetQuantum).Truncate(6).String(),
})
}

Expand All @@ -190,7 +190,7 @@ func (f *FeesStats) ToProto(asset string, assetQuantum num.Decimal) *eventspb.Fe
fs.RefereesDiscountApplied = append(fs.RefereesDiscountApplied, &eventspb.PartyAmount{
Party: party,
Amount: amount.String(),
QuantumAmount: amount.ToDecimal().Div(assetQuantum).Truncate(2).String(),
QuantumAmount: amount.ToDecimal().Div(assetQuantum).Truncate(6).String(),
})
}

Expand All @@ -201,7 +201,7 @@ func (f *FeesStats) ToProto(asset string, assetQuantum num.Decimal) *eventspb.Fe
fs.VolumeDiscountApplied = append(fs.VolumeDiscountApplied, &eventspb.PartyAmount{
Party: party,
Amount: amount.String(),
QuantumAmount: amount.ToDecimal().Div(assetQuantum).Truncate(2).String(),
QuantumAmount: amount.ToDecimal().Div(assetQuantum).Truncate(6).String(),
})
}

Expand All @@ -224,7 +224,7 @@ func (f *FeesStats) ToProto(asset string, assetQuantum num.Decimal) *eventspb.Fe
&eventspb.PartyAmount{
Party: party,
Amount: amount.String(),
QuantumAmount: amount.ToDecimal().Div(assetQuantum).Truncate(2).String(),
QuantumAmount: amount.ToDecimal().Div(assetQuantum).Truncate(6).String(),
},
)
}
Expand All @@ -239,7 +239,7 @@ func (f *FeesStats) ToProto(asset string, assetQuantum num.Decimal) *eventspb.Fe
fs.TotalMakerFeesReceived = append(fs.TotalMakerFeesReceived, &eventspb.PartyAmount{
Party: maker,
Amount: amount.String(),
QuantumAmount: amount.ToDecimal().Div(assetQuantum).Truncate(2).String(),
QuantumAmount: amount.ToDecimal().Div(assetQuantum).Truncate(6).String(),
})
}

Expand All @@ -262,7 +262,7 @@ func (f *FeesStats) ToProto(asset string, assetQuantum num.Decimal) *eventspb.Fe
&eventspb.PartyAmount{
Party: maker,
Amount: amount.String(),
QuantumAmount: amount.ToDecimal().Div(assetQuantum).Truncate(2).String(),
QuantumAmount: amount.ToDecimal().Div(assetQuantum).Truncate(6).String(),
},
)
}
Expand Down
16 changes: 11 additions & 5 deletions datanode/api/trading_data_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,19 @@ func (t *TradingDataServiceV2) GetVestingBalancesSummary(
outVesting = make([]*eventspb.PartyVestingBalance, 0, len(vestingBalances))
outLocked = make([]*eventspb.PartyLockedBalance, 0, len(lockedBalances))
epoch *uint64
setEpoch = func(e uint64) {
if epoch == nil {
epoch = ptr.From(e)
return
}
if *epoch < e {
epoch = ptr.From(e)
}
}
)
if len(vestingBalances) > 0 {
epoch = ptr.From(vestingBalances[0].AtEpoch)
} else if len(lockedBalances) > 0 {
epoch = ptr.From(lockedBalances[0].AtEpoch)
}

for _, v := range vestingBalances {
setEpoch(v.AtEpoch)
outVesting = append(
outVesting, &eventspb.PartyVestingBalance{
Asset: v.AssetID.String(),
Expand All @@ -202,6 +207,7 @@ func (t *TradingDataServiceV2) GetVestingBalancesSummary(
}

for _, v := range lockedBalances {
setEpoch(v.AtEpoch)
outLocked = append(
outLocked, &eventspb.PartyLockedBalance{
Asset: v.AssetID.String(),
Expand Down
2 changes: 1 addition & 1 deletion datanode/sqlstore/party_locked_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (plb *PartyLockedBalance) Prune(
defer metrics.StartSQLQuery("PartyLockedBalance", "Prune")()
_, err := plb.Connection.Exec(
ctx,
"DELETE FROM party_locked_balances_current WHERE until_epoch < $1",
"DELETE FROM party_locked_balances_current WHERE until_epoch <= $1",
currentEpoch,
)

Expand Down

0 comments on commit d098780

Please sign in to comment.