Skip to content

Commit

Permalink
fix: use tickSpacing for bounding
Browse files Browse the repository at this point in the history
  • Loading branch information
Verisana committed Aug 10, 2023
1 parent e11af8f commit 79edf3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/dex/algebra/algebra-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ describe('Algebra', function () {

const tokens = Tokens[network];

const srcTokenSymbol = 'USDC';
const destTokenSymbol = 'WMATIC';
const srcTokenSymbol = 'WMATIC';
const destTokenSymbol = 'DAI';
// const destTokenSymbol = 'USDC';

const amountsForSell = [
0n,
Expand Down
11 changes: 6 additions & 5 deletions src/dex/algebra/lib/TickTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ export class TickTable {
const _row = tickBitmapValue << (255n - bitNumber);
if (_row != 0n) {
tick -= BigInt.asIntN(24, 255n - TickTable.getMostSignificantBit(_row));
return [TickTable.boundTick(tick), true];
return [TickTable.boundTick(tick, tickSpacing), true];
} else {
tick -= BigInt.asIntN(24, bitNumber);
return [TickTable.boundTick(tick), false];
return [TickTable.boundTick(tick, tickSpacing), false];
}
} else {
tick += 1n;
Expand All @@ -112,10 +112,10 @@ export class TickTable {
24,
TickTable.getSingleSignificantBit(-_row & _row),
);
return [TickTable.boundTick(tick), true];
return [TickTable.boundTick(tick, tickSpacing), true];
} else {
tick += BigInt.asIntN(24, 255n - bitNumber);
return [TickTable.boundTick(tick), false];
return [TickTable.boundTick(tick, tickSpacing), false];
}
}
}
Expand Down Expand Up @@ -196,8 +196,9 @@ export class TickTable {
word = word || word >> 16n;
word = word || word >> 32n;
word = word || word >> 64n;
word = word || word >> 128n;
word = word - (word >> 1n);
return TickTable.getSingleSignificantBit(word);
return TickTable.getSingleSignificantBit(BigInt.asUintN(256, word));
}

static boundTick(tick: bigint, tickSpacing?: bigint): bigint {
Expand Down

0 comments on commit 79edf3d

Please sign in to comment.