Skip to content

Commit

Permalink
Merge pull request #10481 from vegaprotocol/fix_pos_migration
Browse files Browse the repository at this point in the history
fix: migrate average entry price to zero if position
  • Loading branch information
jeremyletang authored Jan 25, 2024
2 parents 43228b1 + 7fc28f0 commit e09dc42
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
- [10434](https://github.com/vegaprotocol/vega/issues/10434) - Unsubscribe oracles when market is closed.
- [10454](https://github.com/vegaprotocol/vega/issues/10454) - Fix account resolver validation to include order margin account.
- [10451](https://github.com/vegaprotocol/vega/issues/10451) - Fix get update asset bundle.
- [10480](https://github.com/vegaprotocol/vega/issues/10480) - Fix migration of position average entry price.
- [10419](https://github.com/vegaprotocol/vega/issues/10419) - Block explorer database migration is slow.
- [10431](https://github.com/vegaprotocol/vega/issues/10431) - Fix source staleness validation.
- [10419](https://github.com/vegaprotocol/vega/issues/10419) - Block explorer database migration is slow.
Expand Down
9 changes: 7 additions & 2 deletions core/positions/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"sort"

"code.vegaprotocol.io/vega/core/types"
"code.vegaprotocol.io/vega/libs/num"
"code.vegaprotocol.io/vega/libs/proto"
"code.vegaprotocol.io/vega/libs/ptr"
"code.vegaprotocol.io/vega/logging"
Expand Down Expand Up @@ -104,8 +105,12 @@ func (e *SnapshotEngine) LoadState(_ context.Context, payload *types.Payload) ([

// This is for migration, on the first time we load from snapshot there won't be an average entry price
// so take the last price as the current average
if (p.AverageEntryPrice == nil || p.AverageEntryPrice.IsZero()) && pos.size != 0 && !pos.price.IsZero() {
pos.averageEntryPrice = pos.price.Clone()
if p.AverageEntryPrice == nil {
if pos.size != 0 && !pos.price.IsZero() {
pos.averageEntryPrice = pos.price.Clone()
} else {
pos.averageEntryPrice = num.UintZero()
}
}

// ensure these exists on the first snapshot after the upgrade
Expand Down

0 comments on commit e09dc42

Please sign in to comment.