Skip to content

Commit

Permalink
Merge pull request paraswap#828 from paraswap/fix/algebra-event-handling
Browse files Browse the repository at this point in the history
BACK-1754
  • Loading branch information
KanievskyiDanylo authored Nov 7, 2024
2 parents 012acfa + cc79f95 commit c401b48
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@paraswap/dex-lib",
"version": "3.11.0",
"version": "3.11.1",
"main": "build/index.js",
"types": "build/index.d.ts",
"repository": "https://github.com/paraswap/paraswap-dex-lib",
Expand Down
10 changes: 5 additions & 5 deletions src/dex/algebra/algebra-pool-v1_1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
_reduceTickBitmap,
_reduceTicks,
} from '../uniswap-v3/contract-math/utils';
import { Constants } from './lib/Constants';
import { Network, NULL_ADDRESS } from '../../constants';
import { TickTable } from './lib/TickTable';
import {
Expand Down Expand Up @@ -336,7 +335,8 @@ export class AlgebraEventPoolV1_1 extends StatefulEventSubscriber<PoolStateV1_1>
globalState: { tick },
} = _stateWithoutTicksAndTickBitmap;
const currentBitmapIndex = int16(
(BigInt(tick) / Constants.TICK_SPACING) >> 8n,
(BigInt(tick) / BigInt(_stateWithoutTicksAndTickBitmap.tickSpacing)) >>
8n,
);

const buffer = this.getBitmapRangeToRequest();
Expand Down Expand Up @@ -633,16 +633,16 @@ export class AlgebraEventPoolV1_1 extends StatefulEventSubscriber<PoolStateV1_1>
};
const currentTick = globalState.tick;
const startTickBitmap = TickTable.position(
BigInt(currentTick) / Constants.TICK_SPACING,
BigInt(currentTick) / BigInt(_state.tickSpacing),
)[0];

return {
pool: _state.pool,
blockTimestamp: bigIntify(_state.blockTimestamp),
globalState,
liquidity: bigIntify(_state.liquidity),
tickSpacing: Constants.TICK_SPACING,
maxLiquidityPerTick: Constants.MAX_LIQUIDITY_PER_TICK,
tickSpacing: bigIntify(_state.tickSpacing),
maxLiquidityPerTick: bigIntify(_state.maxLiquidityPerTick),
tickBitmap,
ticks,
startTickBitmap,
Expand Down
10 changes: 5 additions & 5 deletions src/dex/algebra/lib/AlgebraMath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,11 @@ class AlgebraMathClass {
tickCount: 0,
};
// swap until there is remaining input or output tokens or we reach the price limit
let iterationsCount = 0;
while (true) {
iterationsCount++;
_require(iterationsCount < 100, 'Max iteration reached on AlgebraMath');

step.stepSqrtPrice = currentPrice;

//equivalent of tickTable.nextTickInTheSameRow(currentTick, zeroToOne);
Expand Down Expand Up @@ -651,11 +655,7 @@ class AlgebraMathClass {
}

// check stop condition
if (
amountRequired == 0n ||
currentPrice == newSqrtPriceX96 ||
currentTick === newTick // deviation from contract
) {
if (amountRequired == 0n || currentPrice == newSqrtPriceX96) {
break;
}
}
Expand Down

0 comments on commit c401b48

Please sign in to comment.