Skip to content

Commit

Permalink
avoid nil pointer bug for now
Browse files Browse the repository at this point in the history
  • Loading branch information
atvanguard committed Mar 15, 2024
1 parent cb26844 commit aa57ea5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plugin/evm/orderbook/memory_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,11 @@ func (db *InMemoryDatabase) UpdatePosition(trader common.Address, market Market,
db.TraderMap[trader].Positions[market].LiquidationThreshold = getLiquidationThreshold(db.configService.getMaxLiquidationRatio(market), db.configService.getMinSizeRequirement(market), size)
}

// temp hack
if db.TraderMap[trader].Positions[market].LiquidationThreshold == nil {
db.TraderMap[trader].Positions[market].LiquidationThreshold = size
}

// adjust the liquidation threshold if > resultant position size (for both isLiquidation = true/false)
threshold := utils.BigIntMinAbs(db.TraderMap[trader].Positions[market].LiquidationThreshold, size)
db.TraderMap[trader].Positions[market].LiquidationThreshold.Mul(threshold, big.NewInt(int64(size.Sign()))) // same sign as size
Expand Down

0 comments on commit aa57ea5

Please sign in to comment.