Skip to content

Commit 200cab8

Browse files
committed
Pool data fixes
1 parent cee4c12 commit 200cab8

File tree

6 files changed

+43
-28
lines changed

6 files changed

+43
-28
lines changed

src/api/controllers/LiquidityPoolController.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,13 +809,17 @@ export class LiquidityPoolController extends BaseApiController {
809809

810810
const price: number = (entry.latestState.reserveA / 10**tokenADecimals) / (entry.latestState.reserveB / 10**tokenBDecimals);
811811

812+
if (entry.identifier === 'f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c9b65707373c4cec488b16151a64d7102dbae16857c500652b5c513650b8d604e') {
813+
console.log(entry.hour_tick, price)
814+
}
815+
812816
prices.push({
813817
identifier: entry.identifier,
814818
price: price,
815819
dayLow: entry.day_tick ? Math.min(entry.day_tick.low, price) : price,
816820
dayHigh: entry.day_tick ? Math.max(entry.day_tick.high, price) : price,
817821
dayChange: ! entry.day_tick ? 0 : (price - entry.day_tick.close) / entry.day_tick.close * 100,
818-
hourChange: ! entry.hour_tick ? 0 : (price - entry.hour_tick.close) / entry.hour_tick.close * 100,
822+
hourChange: ! entry.hour_tick ? 0 : (price - entry.hour_tick.open) / entry.hour_tick.open * 100,
819823
});
820824

821825
return prices;

src/dex/metadata.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/handlers/AmmOperationHandler.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ export class AmmOperationHandler {
461461
if (! entity) {
462462
return Promise.reject(`Unable to find entity with Tx hash ${operationStatus.operationTxHash}#${operationStatus.operationOutputIndex}`);
463463
}
464-
465464
operationStatus.operationEntity = entity;
466465
operationStatus.operationId = entity.id;
467466
operationStatus.operationType = entity.constructor.name;

src/indexers/AmmDexTransactionIndexer.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { dbService } from '../indexerServices';
66
import { LiquidityPoolState } from '../db/entities/LiquidityPoolState';
77
import { OperationStatus } from '../db/entities/OperationStatus';
88
import { logInfo } from '../logger';
9-
import { formatTransaction } from '../utils';
9+
import { formatTransaction, lucidUtils } from '../utils';
1010
import { AmmOperationHandler } from '../handlers/AmmOperationHandler';
1111

1212
export class AmmDexTransactionIndexer extends BaseIndexer {
@@ -78,14 +78,14 @@ export class AmmDexTransactionIndexer extends BaseIndexer {
7878

7979
async onRollBackward(blockHash: string, slot: Slot): Promise<any> {
8080
// Raw delete with for better performance
81-
await dbService.dbSource.query("DELETE FROM operation_statuses WHERE slot > ?", [slot])
82-
await dbService.dbSource.query("DELETE FROM liquidity_pool_states WHERE slot > ?", [slot])
83-
await dbService.dbSource.query("DELETE FROM liquidity_pool_deposits WHERE slot > ?", [slot])
84-
await dbService.dbSource.query("DELETE FROM liquidity_pool_withdraws WHERE slot > ?", [slot])
85-
await dbService.dbSource.query("DELETE FROM liquidity_pool_swaps WHERE slot > ?", [slot])
86-
await dbService.dbSource.query("DELETE FROM liquidity_pool_zaps WHERE slot > ?", [slot])
87-
await dbService.dbSource.query("DELETE FROM liquidity_pool_zaps WHERE slot > ?", [slot])
88-
await dbService.dbSource.query("DELETE FROM liquidity_pools WHERE createdSlot > ?", [slot])
81+
await dbService.dbSource.query("DELETE FROM operation_statuses WHERE slot > ?", [slot]);
82+
await dbService.dbSource.query("DELETE FROM liquidity_pool_states WHERE slot > ?", [slot]);
83+
await dbService.dbSource.query("DELETE FROM liquidity_pool_deposits WHERE slot > ?", [slot]);
84+
await dbService.dbSource.query("DELETE FROM liquidity_pool_withdraws WHERE slot > ?", [slot]);
85+
await dbService.dbSource.query("DELETE FROM liquidity_pool_swaps WHERE slot > ?", [slot]);
86+
await dbService.dbSource.query("DELETE FROM liquidity_pool_zaps WHERE slot > ?", [slot]);
87+
await dbService.dbSource.query("DELETE FROM liquidity_pools WHERE createdSlot > ?", [slot]);
88+
await dbService.dbSource.query("DELETE FROM liquidity_pool_ticks WHERE time > ?", [lucidUtils.slotToUnixTime(slot) / 1000]);
8989

9090
logInfo('Removed AMM entities');
9191
}

src/jobs/UpdateLiquidityPoolTicks.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { EntityManager } from 'typeorm';
55
import { dbService, eventService, operationWs } from '../indexerServices';
66
import { LiquidityPoolTick } from '../db/entities/LiquidityPoolTick';
77
import { TickInterval } from '../constants';
8-
import { logInfo } from '../logger';
8+
import { logError, logInfo } from '../logger';
99

1010
export class UpdateLiquidityPoolTicks extends BaseJob {
1111

@@ -22,15 +22,17 @@ export class UpdateLiquidityPoolTicks extends BaseJob {
2222

2323
const slotDate: Date = new Date(lucidUtils.slotToUnixTime(this._liquidityPoolState.slot));
2424

25-
const startOfMinute: number = new Date(slotDate.getUTCFullYear(), slotDate.getUTCMonth(), slotDate.getUTCDate(), slotDate.getUTCHours(), slotDate.getUTCMinutes(), 0, 0).getTime() / 1000;
26-
const startOfHour: number = new Date(slotDate.getUTCFullYear(), slotDate.getUTCMonth(), slotDate.getUTCDate(), slotDate.getUTCHours(), 0, 0, 0).getTime() / 1000;
27-
const startOfDay: number = new Date(slotDate.getUTCFullYear(), slotDate.getUTCMonth(), slotDate.getUTCDate(), 0, 0, 0, 0).getTime() / 1000;
25+
const startOfMinute: number = new Date(slotDate.getFullYear(), slotDate.getMonth(), slotDate.getDate(), slotDate.getHours(), slotDate.getMinutes(), 0, 0).getTime() / 1000;
26+
const startOfHour: number = new Date(slotDate.getFullYear(), slotDate.getMonth(), slotDate.getDate(), slotDate.getHours(), 0, 0, 0).getTime() / 1000;
27+
const startOfDay: number = new Date(slotDate.getFullYear(), slotDate.getMonth(), slotDate.getDate(), 0, 0, 0, 0).getTime() / 1000;
2828

2929
return Promise.all([
3030
this.createOrUpdateTick(startOfMinute, TickInterval.Minute),
3131
this.createOrUpdateTick(startOfHour, TickInterval.Hour),
3232
this.createOrUpdateTick(startOfDay, TickInterval.Day)
33-
]);
33+
]).catch((reason) => {
34+
logError(`[Queue] \t UpdateLiquidityPoolTicks failed ${reason}`);
35+
});
3436
}
3537

3638
private async createOrUpdateTick(startOfTick: number, resolution: TickInterval): Promise<any> {
@@ -58,12 +60,16 @@ export class UpdateLiquidityPoolTicks extends BaseJob {
5860
.limit(1)
5961
.getOne() ?? undefined;
6062
});
61-
63+
if (this._liquidityPoolState.liquidityPool.identifier === 'f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c9b65707373c4cec488b16151a64d7102dbae16857c500652b5c513650b8d604e') {
64+
logInfo(`ddddd here 1`)
65+
}
6266
if (! existingTick) {
6367
if (! this._liquidityPoolState.liquidityPool) {
6468
return Promise.reject('Liquidity Pool not found for liquidity pool state');
6569
}
66-
70+
if (this._liquidityPoolState.liquidityPool.identifier === 'f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c9b65707373c4cec488b16151a64d7102dbae16857c500652b5c513650b8d604e') {
71+
logInfo(`ddddd here 2`)
72+
}
6773
const lastTick: LiquidityPoolTick | undefined = await dbService.query((manager: EntityManager) => {
6874
return manager.createQueryBuilder(LiquidityPoolTick, 'ticks')
6975
.where('resolution = :resolution', { resolution })
@@ -76,7 +82,9 @@ export class UpdateLiquidityPoolTicks extends BaseJob {
7682
});
7783

7884
const open: number = lastTick ? lastTick.close : price;
79-
85+
if (this._liquidityPoolState.liquidityPool.identifier === 'f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c9b65707373c4cec488b16151a64d7102dbae16857c500652b5c513650b8d604e') {
86+
logInfo(`ddddd here 3 ${Math.abs(lastTick ? this._liquidityPoolState.tvl - lastTick.tvl : this._liquidityPoolState.tvl)}`)
87+
}
8088
return dbService.transaction((manager: EntityManager) => {
8189
return manager.save(
8290
LiquidityPoolTick.make(
@@ -92,17 +100,21 @@ export class UpdateLiquidityPoolTicks extends BaseJob {
92100
)
93101
).then((tick: LiquidityPoolTick) => {
94102
operationWs.broadcast(tick);
95-
103+
if (this._liquidityPoolState.liquidityPool.identifier === 'f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c9b65707373c4cec488b16151a64d7102dbae16857c500652b5c513650b8d604e') {
104+
logInfo(`ddddd here 3.5 ${tick.time}`)
105+
}
96106
eventService.pushEvent({
97107
type: 'LiquidityPoolTickCreated',
98108
data: tick,
99109
});
100110

101111
return Promise.resolve();
102-
}).catch(() => this.createOrUpdateTick(startOfTick, resolution));
112+
}).catch((reason: any) => this.createOrUpdateTick(startOfTick, resolution));
103113
});
104114
}
105-
115+
if (this._liquidityPoolState.liquidityPool.identifier === 'f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c9b65707373c4cec488b16151a64d7102dbae16857c500652b5c513650b8d604e') {
116+
logInfo(`ddddd here 4`)
117+
}
106118
if (price < existingTick.low) {
107119
existingTick.low = price;
108120
}
@@ -119,7 +131,9 @@ export class UpdateLiquidityPoolTicks extends BaseJob {
119131
return manager.save(existingTick)
120132
.then((tick: LiquidityPoolTick) => {
121133
operationWs.broadcast(tick);
122-
134+
if (this._liquidityPoolState.liquidityPool.identifier === 'f5808c2c990d86da54bfc97d89cee6efa20cd8461616359478d96b4c9b65707373c4cec488b16151a64d7102dbae16857c500652b5c513650b8d604e') {
135+
logInfo(`ddddd here 5`)
136+
}
123137
eventService.pushEvent({
124138
type: 'LiquidityPoolTickUpdated',
125139
data: tick,

src/jobs/UpdateLiquidityPoolTvlJob.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ export class UpdateLiquidityPoolTvlJob extends BaseJob {
2828
this._liquidityPoolState.liquidityPool.tokenA
2929
? this.updateNonAdaPoolTvl(this._liquidityPoolState.liquidityPool)
3030
: this.updateAdaPoolTvl(this._liquidityPoolState.liquidityPool)
31-
).then(() => {
32-
if (this._liquidityPoolState.tvl !== 0) {
33-
queue.dispatch(new UpdateLiquidityPoolTicks(this._liquidityPoolState));
34-
}
31+
).finally(() => {
32+
queue.dispatch(new UpdateLiquidityPoolTicks(this._liquidityPoolState));
3533
})
3634
}
3735

0 commit comments

Comments
 (0)