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

fix: math error in tick updates during swaps #60

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
9 changes: 5 additions & 4 deletions src/mappings/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,9 @@ export function handleSwap(event: SwapEvent): void {
// Update inner vars of current or crossed ticks
let newTick = pool.tick!
let tickSpacing = feeTierToTickSpacing(pool.feeTier)
let modulo = newTick.mod(tickSpacing)
if (modulo.equals(ZERO_BI)) {
let newModulo = newTick.mod(tickSpacing)
let oldModulo = oldTick.mod(tickSpacing)
if (newModulo.equals(ZERO_BI)) {
// Current tick is initialized and needs to be updated
loadTickUpdateFeeVarsAndSave(newTick.toI32(), event)
}
Expand All @@ -477,12 +478,12 @@ export function handleSwap(event: SwapEvent): void {
// updated later. For early users this error also disappears when calling
// collect
} else if (newTick.gt(oldTick)) {
let firstInitialized = oldTick.plus(tickSpacing.minus(modulo))
let firstInitialized = oldTick.plus(tickSpacing.minus(oldModulo))
for (let i = firstInitialized; i.le(newTick); i = i.plus(tickSpacing)) {
loadTickUpdateFeeVarsAndSave(i.toI32(), event)
}
} else if (newTick.lt(oldTick)) {
let firstInitialized = oldTick.minus(modulo)
let firstInitialized = oldTick.minus(oldModulo)
for (let i = firstInitialized; i.ge(newTick); i = i.minus(tickSpacing)) {
loadTickUpdateFeeVarsAndSave(i.toI32(), event)
}
Expand Down