Skip to content

Commit

Permalink
Merge pull request #13 from oraichain/add/pool-info
Browse files Browse the repository at this point in the history
Add/pool info
  • Loading branch information
trungbach authored Sep 15, 2023
2 parents f88b28f + b177df9 commit 73317f2
Show file tree
Hide file tree
Showing 15 changed files with 2,629 additions and 545 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"test": "jest",
"docs": "typedoc --entryPointStrategy expand --name 'Oraidex SDK' --readme none --tsconfig packages/contracts-sdk/tsconfig.json packages/contracts-sdk/src",
"build": "tsc -p",
"deploy": "yarn publish --access public --patch",
"start:server": "yarn build packages/oraidex-sync/ && npx ts-node packages/oraidex-server/src/index.ts"
"deploy": "yarn publish --access public",
"start:server": "yarn build packages/oraidex-sync/ && npx ts-node-dev packages/oraidex-server/src/index.ts"
},
"workspaces": [
"packages/*"
Expand Down
64 changes: 47 additions & 17 deletions packages/oraidex-server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
#!/usr/bin/env node

import "dotenv/config";
import express, { Request } from "express";
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { OraiswapRouterQueryClient } from "@oraichain/oraidex-contracts-sdk";
import {
DuckDb,
GetCandlesQuery,
ORAI,
OraiDexSync,
PairInfoDataResponse,
TickerInfo,
VolumeRange,
findPairAddress,
getAllFees,
getAllVolume24h,
getPairLiquidity,
oraiUsdtPairOnlyDenom,
pairs,
pairsOnlyDenom,
parseAssetInfoOnlyDenom,
findPairAddress,
toDisplay,
OraiDexSync,
simulateSwapPrice,
pairsOnlyDenom,
VolumeRange,
oraiUsdtPairOnlyDenom,
ORAI
toDisplay
} from "@oraichain/oraidex-sync";
import cors from "cors";
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";
import { OraiswapRouterQueryClient } from "@oraichain/oraidex-contracts-sdk";
import { getDate24hBeforeNow, getSpecificDateBeforeNow, pairToString, parseSymbolsToTickerId } from "./helper";
import { GetCandlesQuery } from "@oraichain/oraidex-sync";
import "dotenv/config";
import express, { Request } from "express";
import fs from "fs";
import path from "path";
import { getDate24hBeforeNow, getSpecificDateBeforeNow, pairToString, parseSymbolsToTickerId } from "./helper";

const app = express();
app.use(cors());
Expand Down Expand Up @@ -79,7 +83,6 @@ app.get("/tickers", async (req, res) => {
const symbols = pair.symbols;
const pairAddr = findPairAddress(pairInfos, pair.asset_infos);
const tickerId = parseSymbolsToTickerId(symbols);
// const { baseIndex, targetIndex, target } = findUsdOraiInPair(pair.asset_infos);
const baseIndex = 0;
const targetIndex = 1;
console.log(latestTimestamp, then);
Expand Down Expand Up @@ -215,7 +218,7 @@ app.get("/volume/v2/historical/chart", async (req, res) => {
// console.log("prefix sum: ", prefixSum);
// res.status(200).send("hello world");
// } catch (error) {
// console.log("server error /liquidity/v2/historical/chart: ", error);
// console.log("server error /liquidity/v2/historical/chart: ", error);
// res.status(500).send(JSON.stringify(error));
// } finally {
// return;
Expand All @@ -231,10 +234,37 @@ app.get("/v1/candles/", async (req: Request<{}, {}, {}, GetCandlesQuery>, res) =
}
});

app.get("/v1/pools/", async (_req, res) => {
try {
const [volumes, allFee7Days, pools, allPoolApr] = await Promise.all([
getAllVolume24h(),
getAllFees(),
duckDb.getPools(),
duckDb.getApr()
]);
const allLiquidities = await Promise.all(pools.map((pair) => getPairLiquidity(pair)));

res.status(200).send(
pools.map((pool, index) => {
const poolApr = allPoolApr.find((item) => item.pairAddr === pool.pairAddr);
return {
...pool,
volume24Hour: volumes[index]?.toString() ?? "0",
fee7Days: allFee7Days[index]?.toString() ?? "0",
apr: poolApr?.apr ?? 0,
totalLiquidity: allLiquidities[index]
} as PairInfoDataResponse;
})
);
} catch (error) {
console.log({ error });
res.status(500).send(error.message);
}
});

app.listen(port, hostname, async () => {
// sync data for the service to read
// console.dir(pairInfos, { depth: null });
duckDb = await DuckDb.create(process.env.DUCKDB_PROD_FILENAME || "oraidex-sync-data");
duckDb = await DuckDb.create(process.env.DUCKDB_PROD_FILENAME);
const oraidexSync = await OraiDexSync.create(
duckDb,
process.env.RPC_URL || "https://rpc.orai.io",
Expand Down
18 changes: 18 additions & 0 deletions packages/oraidex-sync/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AssetInfo } from "@oraichain/common-contracts-sdk";

export const ORAI = "orai";
export const airiCw20Adress = "orai10ldgzued6zjp0mkqwsv2mux3ml50l97c74x8sg";
export const oraixCw20Address = "orai1lus0f0rhx8s03gdllx2n6vhkmf0536dv57wfge";
Expand All @@ -13,3 +15,19 @@ export const osmosisIbcDenom = "ibc/9C4DCD21B48231D0BC2AC3D1B74A864746B37E429269
export const tenAmountInDecimalSix = 10000000;
export const truncDecimals = 6;
export const atomic = 10 ** truncDecimals;
export const oraiInfo: AssetInfo = { native_token: { denom: ORAI } };
export const usdtInfo: AssetInfo = { token: { contract_addr: usdtCw20Address } };
export const ORAIXOCH_INFO: AssetInfo = {
token: {
contract_addr: "orai1lplapmgqnelqn253stz6kmvm3ulgdaytn89a8mz9y85xq8wd684s6xl3lt"
}
};

export const SEC_PER_YEAR = 60 * 60 * 24 * 365;
export const network = {
factory: process.env.FACTORY_CONTACT_ADDRESS_V1,
factory_v2: process.env.FACTORY_CONTACT_ADDRESS_V2,
router: process.env.ROUTER_CONTRACT_ADDRESS,
staking: process.env.STAKING_CONTRACT,
multicall: process.env.MULTICALL_CONTRACT_ADDRESS
};
Loading

0 comments on commit 73317f2

Please sign in to comment.