Skip to content
Open
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
11 changes: 7 additions & 4 deletions src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,14 @@ function subOrder(id: string, amount: BigInt, base: string, quote: string, direc
bin.save()
} else {
increment.orders = orders
increment.amount = increment.amount.minus(amount)
if (increment.amount.lt(BigInt.zero())) {
// TODO: figure out why this happens
// throw new Error("increment negative: " + incrementId + " amount: " + increment.amount.toString())

// There may arise situations where div rounding error in inverseAmount calcs causes amount to be greater than increment amount
// In this case set increment.amount to zero versus negative and save
if (increment.amount.lt(amount)) {
increment.amount = BigInt.zero()
increment.save()
} else {
increment.amount = increment.amount.minus(amount)
increment.save()
}
}
Expand Down