Skip to content

Commit

Permalink
refactor: remove v1 history and rename v2 history to just history
Browse files Browse the repository at this point in the history
  • Loading branch information
tmrdlt committed Apr 25, 2024
1 parent 72605bb commit 9ec0a79
Show file tree
Hide file tree
Showing 30 changed files with 1,143 additions and 2,190 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 0 additions & 48 deletions prisma/migrations/20240423120012_history_v2/migration.sql

This file was deleted.

49 changes: 49 additions & 0 deletions prisma/migrations/20240425094014_history_v2/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Warnings:
- You are about to drop the column `totalSupply` on the `PairLiquidityInfoHistory` table. All the data in the column will be lost.
- A unique constraint covering the columns `[pairId,microBlockHash,transactionHash,logIndex]` on the table `PairLiquidityInfoHistory` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[pairId,microBlockHash,transactionHash,logIndex,error]` on the table `PairLiquidityInfoHistoryError` will be added. If there are existing duplicate values, this will fail.
- Added the required column `aeUsdPrice` to the `PairLiquidityInfoHistory` table without a default value. This is not possible if the table is not empty.
- Added the required column `deltaReserve0` to the `PairLiquidityInfoHistory` table without a default value. This is not possible if the table is not empty.
- Added the required column `deltaReserve1` to the `PairLiquidityInfoHistory` table without a default value. This is not possible if the table is not empty.
- Added the required column `eventType` to the `PairLiquidityInfoHistory` table without a default value. This is not possible if the table is not empty.
- Added the required column `logIndex` to the `PairLiquidityInfoHistory` table without a default value. This is not possible if the table is not empty.
- Added the required column `transactionHash` to the `PairLiquidityInfoHistory` table without a default value. This is not possible if the table is not empty.
- Added the required column `transactionIndex` to the `PairLiquidityInfoHistory` table without a default value. This is not possible if the table is not empty.
- Changed the type of `reserve0` on the `PairLiquidityInfoHistory` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
- Changed the type of `reserve1` on the `PairLiquidityInfoHistory` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
- Added the required column `logIndex` to the `PairLiquidityInfoHistoryError` table without a default value. This is not possible if the table is not empty.
- Added the required column `transactionHash` to the `PairLiquidityInfoHistoryError` table without a default value. This is not possible if the table is not empty.
*/
-- DropIndex
DROP INDEX "PairLiquidityInfoHistory_pairId_microBlockHash_key";

-- DropIndex
DROP INDEX "PairLiquidityInfoHistoryError_pairId_microBlockHash_error_key";

-- AlterTable
ALTER TABLE "PairLiquidityInfoHistory" DROP COLUMN "totalSupply",
ADD COLUMN "aeUsdPrice" DECIMAL(100,6) NOT NULL,
ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "deltaReserve0" DECIMAL(100,0) NOT NULL,
ADD COLUMN "deltaReserve1" DECIMAL(100,0) NOT NULL,
ADD COLUMN "eventType" TEXT NOT NULL,
ADD COLUMN "logIndex" INTEGER NOT NULL,
ADD COLUMN "transactionHash" TEXT NOT NULL,
ADD COLUMN "transactionIndex" BIGINT NOT NULL,
DROP COLUMN "reserve0",
ADD COLUMN "reserve0" DECIMAL(100,0) NOT NULL,
DROP COLUMN "reserve1",
ADD COLUMN "reserve1" DECIMAL(100,0) NOT NULL;

-- AlterTable
ALTER TABLE "PairLiquidityInfoHistoryError" ADD COLUMN "logIndex" INTEGER NOT NULL,
ADD COLUMN "transactionHash" TEXT NOT NULL;

-- CreateIndex
CREATE UNIQUE INDEX "PairLiquidityInfoHistory_pairId_microBlockHash_transactionH_key" ON "PairLiquidityInfoHistory"("pairId", "microBlockHash", "transactionHash", "logIndex");

-- CreateIndex
CREATE UNIQUE INDEX "PairLiquidityInfoHistoryError_pairId_microBlockHash_transac_key" ON "PairLiquidityInfoHistoryError"("pairId", "microBlockHash", "transactionHash", "logIndex", "error");
52 changes: 11 additions & 41 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ model Token {
}

model Pair {
id Int @id @default(autoincrement())
address String @unique
token0 Token @relation("Pair_Token0", fields: [t0], references: [id])
t0 Int
token1 Token @relation("Pair_Token1", fields: [t1], references: [id])
t1 Int
liquidityInfo PairLiquidityInfo? @relation("Pair_Info")
synchronized Boolean
liquidityInfoHistory PairLiquidityInfoHistory[]
liquidityInfoHistoryV2 PairLiquidityInfoHistoryV2[]
liquidityInfoHistoryError PairLiquidityInfoHistoryError[]
liquidityInfoHistoryV2Error PairLiquidityInfoHistoryV2Error[]
id Int @id @default(autoincrement())
address String @unique
token0 Token @relation("Pair_Token0", fields: [t0], references: [id])
t0 Int
token1 Token @relation("Pair_Token1", fields: [t1], references: [id])
t1 Int
liquidityInfo PairLiquidityInfo? @relation("Pair_Info")
synchronized Boolean
liquidityInfoHistory PairLiquidityInfoHistory[]
liquidityInfoHistoryError PairLiquidityInfoHistoryError[]
}

model PairLiquidityInfo {
Expand All @@ -49,34 +47,6 @@ model PairLiquidityInfo {
}

model PairLiquidityInfoHistory {
id Int @id @default(autoincrement())
pair Pair @relation(fields: [pairId], references: [id])
pairId Int
totalSupply String
reserve0 String
reserve1 String
height Int
microBlockHash String
microBlockTime BigInt
updatedAt DateTime @default(now()) @updatedAt
@@unique(name: "pairIdMicroBlockHashUniqueIndex", [pairId, microBlockHash])
}

model PairLiquidityInfoHistoryError {
id Int @id @default(autoincrement())
pair Pair @relation(fields: [pairId], references: [id])
pairId Int
microBlockHash String
error String
timesOccurred Int @default(1)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
@@unique(name: "pairIdMicroBlockHashErrorUniqueIndex", [pairId, microBlockHash, error])
}

model PairLiquidityInfoHistoryV2 {
id Int @id @default(autoincrement())
pair Pair @relation(fields: [pairId], references: [id])
pairId Int
Expand All @@ -98,7 +68,7 @@ model PairLiquidityInfoHistoryV2 {
@@unique(name: "pairIdMicroBlockHashTxHashLogIndexUniqueIndex", [pairId, microBlockHash, transactionHash, logIndex])
}

model PairLiquidityInfoHistoryV2Error {
model PairLiquidityInfoHistoryError {
id Int @id @default(autoincrement())
pair Pair @relation(fields: [pairId], references: [id])
pairId Int
Expand Down
1 change: 1 addition & 0 deletions src/api/api.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export enum OrderQueryEnum {
desc = 'desc',
}

// TODO adjust
export class PairLiquidityInfoHistoryEntry {
@ApiProperty(pairAddressPropertyOptions)
pairAddress: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,93 +34,94 @@ describe('PairLiquidityInfoHistoryController', () => {
jest.clearAllMocks();
});

it('should return history entries and use default values for empty params', async () => {
// Mocks
const historyEntry1: { pair: Pair } & PairLiquidityInfoHistory = {
id: 1,
pairId: 1,
totalSupply: '2000148656239820912122563',
reserve0: '950875688379385634428666',
reserve1: '4208476309359648851631167',
height: 912485,
microBlockHash: 'mh_Tx43Gh3acudUNSUWihPcV1Se4XcoFK3aUFAtFZk2Z4Zv7igZs',
microBlockTime: 1709027642807n,
updatedAt: new Date('2024-03-20 17:04:51.625'),
pair: {
id: 1,
address: 'ct_efYtiwDg4YZxDWE3iLPzvrjb92CJPvzGwriv4ZRuvuTDMNMb9',
t0: 15,
t1: 5,
synchronized: true,
},
};

const historyEntry2: { pair: Pair } & PairLiquidityInfoHistory = {
id: 2,
pairId: 3,
totalSupply: '9954575303087659158151',
reserve0: '20210309618736130321327',
reserve1: '4903471477408475598460',
height: 707395,
microBlockHash: 'mh_2dUTfmwFc2ymeroB534giVwEvsa8d44Vf8SXtvy6GeHjdgQoHj',
microBlockTime: 1671708830503n,
updatedAt: new Date('2024-03-20 12:16:49.065'),
pair: {
id: 3,
address: 'ct_22iY9F7hng23gN8awi4aGnLy54YSR41wztbqgQCquuLYvTiGcm',
t0: 17,
t1: 22,
synchronized: true,
},
};

mockPairLiquidityInfoHistoryService.getAllHistoryEntries.mockResolvedValue(
[historyEntry1, historyEntry2],
);

// Call route
const result = await request(app.getHttpServer()).get(
'/history/liquidity',
);

// Assertions
expect(
mockPairLiquidityInfoHistoryService.getAllHistoryEntries,
).toHaveBeenCalledWith(
100,
0,
OrderQueryEnum.asc,
undefined,
undefined,
undefined,
undefined,
);
expect(result.status).toBe(200);
expect(result.body).toEqual([
{
pairAddress: historyEntry1.pair.address,
liquidityInfo: {
totalSupply: historyEntry1.totalSupply,
reserve0: historyEntry1.reserve0,
reserve1: historyEntry1.reserve1,
},
height: historyEntry1.height,
microBlockHash: historyEntry1.microBlockHash,
microBlockTime: historyEntry1.microBlockTime.toString(),
},
{
pairAddress: historyEntry2.pair.address,
liquidityInfo: {
totalSupply: historyEntry2.totalSupply,
reserve0: historyEntry2.reserve0,
reserve1: historyEntry2.reserve1,
},
height: historyEntry2.height,
microBlockHash: historyEntry2.microBlockHash,
microBlockTime: historyEntry2.microBlockTime.toString(),
},
]);
});
// TODO fix with updated return
// it('should return history entries and use default values for empty params', async () => {
// // Mocks
// const historyEntry1: { pair: Pair } & PairLiquidityInfoHistory = {
// id: 1,
// pairId: 1,
// totalSupply: '2000148656239820912122563',
// reserve0: '950875688379385634428666',
// reserve1: '4208476309359648851631167',
// height: 912485,
// microBlockHash: 'mh_Tx43Gh3acudUNSUWihPcV1Se4XcoFK3aUFAtFZk2Z4Zv7igZs',
// microBlockTime: 1709027642807n,
// updatedAt: new Date('2024-03-20 17:04:51.625'),
// pair: {
// id: 1,
// address: 'ct_efYtiwDg4YZxDWE3iLPzvrjb92CJPvzGwriv4ZRuvuTDMNMb9',
// t0: 15,
// t1: 5,
// synchronized: true,
// },
// };
//
// const historyEntry2: { pair: Pair } & PairLiquidityInfoHistory = {
// id: 2,
// pairId: 3,
// totalSupply: '9954575303087659158151',
// reserve0: '20210309618736130321327',
// reserve1: '4903471477408475598460',
// height: 707395,
// microBlockHash: 'mh_2dUTfmwFc2ymeroB534giVwEvsa8d44Vf8SXtvy6GeHjdgQoHj',
// microBlockTime: 1671708830503n,
// updatedAt: new Date('2024-03-20 12:16:49.065'),
// pair: {
// id: 3,
// address: 'ct_22iY9F7hng23gN8awi4aGnLy54YSR41wztbqgQCquuLYvTiGcm',
// t0: 17,
// t1: 22,
// synchronized: true,
// },
// };
//
// mockPairLiquidityInfoHistoryService.getAllHistoryEntries.mockResolvedValue(
// [historyEntry1, historyEntry2],
// );
//
// // Call route
// const result = await request(app.getHttpServer()).get(
// '/history/liquidity',
// );
//
// // Assertions
// expect(
// mockPairLiquidityInfoHistoryService.getAllHistoryEntries,
// ).toHaveBeenCalledWith(
// 100,
// 0,
// OrderQueryEnum.asc,
// undefined,
// undefined,
// undefined,
// undefined,
// );
// expect(result.status).toBe(200);
// expect(result.body).toEqual([
// {
// pairAddress: historyEntry1.pair.address,
// liquidityInfo: {
// totalSupply: historyEntry1.totalSupply,
// reserve0: historyEntry1.reserve0,
// reserve1: historyEntry1.reserve1,
// },
// height: historyEntry1.height,
// microBlockHash: historyEntry1.microBlockHash,
// microBlockTime: historyEntry1.microBlockTime.toString(),
// },
// {
// pairAddress: historyEntry2.pair.address,
// liquidityInfo: {
// totalSupply: historyEntry2.totalSupply,
// reserve0: historyEntry2.reserve0,
// reserve1: historyEntry2.reserve1,
// },
// height: historyEntry2.height,
// microBlockHash: historyEntry2.microBlockHash,
// microBlockTime: historyEntry2.microBlockTime.toString(),
// },
// ]);
// });

it('should parse all query params correctly', async () => {
// Mocks
Expand Down
Loading

0 comments on commit 9ec0a79

Please sign in to comment.