Skip to content

Commit

Permalink
Merge pull request #46 from oraichain/staging
Browse files Browse the repository at this point in the history
Re-calculate volume pools
  • Loading branch information
trungbach authored Nov 9, 2023
2 parents 79e7a9f + 70953bb commit 482375e
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 54 deletions.
2 changes: 1 addition & 1 deletion packages/oraidex-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oraichain/oraidex-server",
"version": "1.0.17",
"version": "1.0.18",
"main": "dist/index.js",
"bin": "dist/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/oraidex-server/package.staging.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oraichain/oraidex-server-staging",
"version": "1.0.16",
"version": "1.0.17",
"main": "dist/index.js",
"bin": "dist/index.js",
"license": "MIT",
Expand Down
20 changes: 0 additions & 20 deletions packages/oraidex-sync/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,26 +469,6 @@ export class DuckDb {
return BigInt(result[0]?.totalVolume ?? 0);
}

async getVolumeLiquidity(payload: GetFeeSwap): Promise<bigint> {
const { offerDenom, askDenom, startTime, endTime } = payload;
const result = await this.conn.all(
`
SELECT
sum(baseTokenAmount) as totalVolume,
FROM lp_ops_data
WHERE timestamp >= ?
AND timestamp <= ?
AND baseTokenDenom = ?
AND quoteTokenDenom = ?
`,
startTime,
endTime,
offerDenom,
askDenom
);
return BigInt(result[0]?.totalVolume ?? 0);
}

async createLpAmountHistoryTable() {
await this.conn.exec(
`CREATE TABLE IF NOT EXISTS lp_amount_history (
Expand Down
23 changes: 7 additions & 16 deletions packages/oraidex-sync/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,23 +390,14 @@ export const getVolumePairByAsset = async (
): Promise<bigint> => {
const duckDb = DuckDb.instances;
const pair = `${baseDenom}-${quoteDenom}`;
const [volumeSwapPairInBaseAsset, volumeLiquidityPairInBaseAsset] = await Promise.all([
duckDb.getVolumeSwap({
pair,
startTime: convertDateToSecond(startTime),
endTime: convertDateToSecond(endTime)
}),
duckDb.getVolumeLiquidity({
offerDenom: baseDenom,
askDenom: quoteDenom,
startTime: convertDateToSecond(startTime),
endTime: convertDateToSecond(endTime)
})
]);

// sum of base & quote asset volume.
const totalVolumeLiquidityPair = volumeLiquidityPairInBaseAsset * 2n;
return volumeSwapPairInBaseAsset + totalVolumeLiquidityPair;
const volumeSwapPairInBaseAsset = await duckDb.getVolumeSwap({
pair,
startTime: convertDateToSecond(startTime),
endTime: convertDateToSecond(endTime)
});

return volumeSwapPairInBaseAsset;
};

export const getVolumePairByUsdt = async (
Expand Down
14 changes: 0 additions & 14 deletions packages/oraidex-sync/tests/db.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,20 +413,6 @@ describe("test-duckdb", () => {
// assertion
expect(feeSwap).toEqual(3n);
});

it("test-getVolumeLiquidity-should-return-correctly-volume-liquidity-in-base-asset", async () => {
// act
const payload: GetFeeSwap = {
offerDenom: "orai",
askDenom: "atom",
startTime: 1589610068000 / 1000,
endTime: 1689610068000 / 1000
};
const volumeByBaseAsset = await duckDb.getVolumeLiquidity(payload);

// assertion
expect(volumeByBaseAsset).toEqual(2n);
});
});

describe("test-apr", () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/oraidex-sync/tests/helper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,13 +723,12 @@ describe("test-helper", () => {
it("test-getVolumePairByAsset-should-return-correctly-sum-volume-swap-&-liquidity", async () => {
// setup mock
jest.spyOn(duckDb, "getVolumeSwap").mockResolvedValue(1n);
jest.spyOn(duckDb, "getVolumeLiquidity").mockResolvedValue(1n);

// act
const result = await getVolumePairByAsset(["orai", "usdt"], new Date(1693394183), new Date(1693394183));

// assert
expect(result).toEqual(3n);
expect(result).toEqual(1n);
});

it("test-getVolumePairByUsdt-should-return-correctly-volume-pair-in-USDT", async () => {
Expand Down

0 comments on commit 482375e

Please sign in to comment.