From 999aa785533880dc7f2145de72e3fa7e2f808d95 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Sat, 17 Feb 2024 19:43:53 +0700 Subject: [PATCH 01/14] add pool ntmpi usdc --- packages/oraidex-common/package.json | 2 +- packages/oraidex-common/src/network.ts | 2 +- packages/oraidex-common/src/pairs.ts | 14 ++++++++++---- packages/oraidex-sync/src/pairs.ts | 7 ++++++- packages/oraidex-sync/tests/helper.spec.ts | 10 +++++++++- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/packages/oraidex-common/package.json b/packages/oraidex-common/package.json index b6f6d7ff..ae64ef0b 100644 --- a/packages/oraidex-common/package.json +++ b/packages/oraidex-common/package.json @@ -1,6 +1,6 @@ { "name": "@oraichain/oraidex-common", - "version": "1.0.66", + "version": "1.0.67", "main": "build/index.js", "files": [ "build/" diff --git a/packages/oraidex-common/src/network.ts b/packages/oraidex-common/src/network.ts index 3bcdd3a9..958ebb18 100644 --- a/packages/oraidex-common/src/network.ts +++ b/packages/oraidex-common/src/network.ts @@ -312,7 +312,7 @@ export const oraichainNetwork: CustomChainInfo = { coinImageUrl: "https://dhj8dql1kzq2v.cloudfront.net/white/atom.png" }, { - coinDenom: "NEUTARO", + coinDenom: "NTMPI", coinGeckoId: "neutaro", coinMinimalDenom: NEUTARO_ORAICHAIN_DENOM, bridgeTo: ["Neutaro-1"], diff --git a/packages/oraidex-common/src/pairs.ts b/packages/oraidex-common/src/pairs.ts index 635c9e9d..49a046d4 100644 --- a/packages/oraidex-common/src/pairs.ts +++ b/packages/oraidex-common/src/pairs.ts @@ -14,7 +14,8 @@ import { TRX_CONTRACT, USDC_CONTRACT, USDT_CONTRACT, - WETH_CONTRACT + WETH_CONTRACT, + NEUTARO_ORAICHAIN_DENOM } from "./constant"; import { parseAssetInfo } from "./helper"; import { TokenItemType, assetInfoMap } from "./token"; @@ -92,9 +93,13 @@ export const PAIRS: PairMapping[] = [ symbols: ["ORAI", "WETH"] }, { - asset_infos: [{ native_token: { denom: ORAI } }, { token: { contract_addr: BTC_CONTRACT } }], - symbols: ["ORAI", "BTC"] + asset_infos: [{ native_token: { denom: NEUTARO_ORAICHAIN_DENOM } }, { token: { contract_addr: USDC_CONTRACT } }], + symbols: ["NTMPI", "USDC"] } + // { + // asset_infos: [{ native_token: { denom: ORAI } }, { token: { contract_addr: BTC_CONTRACT } }], + // symbols: ["ORAI", "BTC"] + // } ]; // FIXME: makes this dynamic in the future so that permissionless listing is simpler @@ -113,7 +118,8 @@ export enum pairLpTokens { INJ_ORAI = "orai1slqw6gfvs6l2jgvh5ryjayf4g77d7sgfv6fumtyzcr06a6g9gnrq6c4rgg", USDC_ORAIX = "orai1nwpfd09mr4rf8d5c9mh43axzezkwyr7dq2lus23jsw4xw2jqkaxqxwmkd3", ORAI_WETH = "orai1rvr9wk6mdlfysvgp72ltthqvkkd5677mp892efq86yyr9alt0tms2a6lcs", - ORAI_BTC = "orai1jd9lc2qt0ltjsatgnu38xsz8ngp89clp0dpeh8geyjj70yvkn4kqmrmh3m" + ORAI_BTC = "orai1jd9lc2qt0ltjsatgnu38xsz8ngp89clp0dpeh8geyjj70yvkn4kqmrmh3m", + NTMPI_USDC = "orai1rmvjmwd940ztafxue7630g75px8tqma4jskjuu57fkj0eqahqfgqqwjm00" } // token identifier can be denom or contract addr diff --git a/packages/oraidex-sync/src/pairs.ts b/packages/oraidex-sync/src/pairs.ts index 17f96484..9b15321f 100644 --- a/packages/oraidex-sync/src/pairs.ts +++ b/packages/oraidex-sync/src/pairs.ts @@ -17,7 +17,7 @@ import { usdtCw20Address } from "./constants"; import { PairMapping } from "./types"; -import { WETH_CONTRACT } from "@oraichain/oraidex-common/build/constant"; +import { WETH_CONTRACT, NEUTARO_ORAICHAIN_DENOM } from "@oraichain/oraidex-common/build/constant"; import { pairLpTokens } from "@oraichain/oraidex-common/build/pairs"; // the orders are important! Do not change the order of the asset_infos. @@ -104,6 +104,11 @@ export const pairs: PairMapping[] = [ asset_infos: [{ native_token: { denom: ORAI } }, { token: { contract_addr: WETH_CONTRACT } }], lp_token: pairLpTokens.ORAI_WETH, symbols: ["ORAI", "WETH"] + }, + { + asset_infos: [{ native_token: { denom: NEUTARO_ORAICHAIN_DENOM } }, { token: { contract_addr: usdcCw20Address } }], + lp_token: pairLpTokens.NTMPI_USDC, + symbols: ["NTMPI", "USDC"] } ]; diff --git a/packages/oraidex-sync/tests/helper.spec.ts b/packages/oraidex-sync/tests/helper.spec.ts index 963d253f..14b3aab3 100644 --- a/packages/oraidex-sync/tests/helper.spec.ts +++ b/packages/oraidex-sync/tests/helper.spec.ts @@ -38,7 +38,7 @@ import * as poolHelper from "../src/pool-helper"; import * as helper from "../src/helper"; import * as parse from "../src/parse"; import { SwapOperation } from "@oraichain/oraidex-contracts-sdk/build/OraiswapRouter.types"; -import { WETH_CONTRACT, pairLpTokens } from "@oraichain/oraidex-common"; +import { NEUTARO_ORAICHAIN_DENOM, WETH_CONTRACT, pairLpTokens } from "@oraichain/oraidex-common"; describe("test-helper", () => { let duckDb: DuckDb; @@ -237,6 +237,14 @@ describe("test-helper", () => { asset_infos: [{ native_token: { denom: ORAI } }, { token: { contract_addr: WETH_CONTRACT } }], lp_token: pairLpTokens.ORAI_WETH, symbols: ["ORAI", "WETH"] + }, + { + asset_infos: [ + { native_token: { denom: NEUTARO_ORAICHAIN_DENOM } }, + { token: { contract_addr: usdcCw20Address } } + ], + lp_token: pairLpTokens.NTMPI_USDC, + symbols: ["NTMPI", "USDC"] } ]); }); From dda678fdea6ea3fc02fe1d978f01c11884405fdc Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Sun, 18 Feb 2024 13:53:15 +0700 Subject: [PATCH 02/14] add pool ntmpi usdc --- .eslintrc.json | 31 ++++---------- packages/oraidex-common/src/pairs.ts | 8 ++-- packages/oraidex-server/src/polyfill.ts | 25 ++++++------ .../tests/polyfill-tendermint.spec.ts | 16 ++++---- packages/oraidex-sync/src/pairs.ts | 7 +++- packages/oraidex-sync/src/pool-helper.ts | 8 ++-- packages/oraidex-sync/src/query.ts | 40 ++++++++++++------- packages/oraidex-sync/tests/helper.spec.ts | 7 +++- 8 files changed, 75 insertions(+), 67 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index d77e49cc..017fb198 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,39 +21,24 @@ "typescript": true } }, - "plugins": [ - "@typescript-eslint" - ], + "plugins": ["@typescript-eslint"], "rules": { "no-console": "off", - "quotes": [ - "error", - "double" - ], - "semi": [ - "error", - "always" - ] + "quotes": ["error", "double"], + "semi": ["error", "always"] }, "overrides": [ { - "files": [ - "*.ts", - "*.tsx" - ], + "files": ["*.ts", "*.tsx"], "rules": { - "@typescript-eslint/no-explicit-any": [ - "warn" - ], + "@typescript-eslint/no-explicit-any": ["warn"], "@typescript-eslint/no-unused-vars": "warn", - "security/detect-object-injection": "off", - "@typescript-eslint/ban-ts-comment": "off" + "security/detect-object-injection": "off" + // "@typescript-eslint/ban-ts-comment": "off" } }, { - "files": [ - "*.js" - ], + "files": ["*.js"], "rules": { "@typescript-eslint/no-var-requires": "warn" } diff --git a/packages/oraidex-common/src/pairs.ts b/packages/oraidex-common/src/pairs.ts index 49a046d4..063511f8 100644 --- a/packages/oraidex-common/src/pairs.ts +++ b/packages/oraidex-common/src/pairs.ts @@ -95,11 +95,11 @@ export const PAIRS: PairMapping[] = [ { asset_infos: [{ native_token: { denom: NEUTARO_ORAICHAIN_DENOM } }, { token: { contract_addr: USDC_CONTRACT } }], symbols: ["NTMPI", "USDC"] + }, + { + asset_infos: [{ native_token: { denom: ORAI } }, { token: { contract_addr: BTC_CONTRACT } }], + symbols: ["ORAI", "BTC"] } - // { - // asset_infos: [{ native_token: { denom: ORAI } }, { token: { contract_addr: BTC_CONTRACT } }], - // symbols: ["ORAI", "BTC"] - // } ]; // FIXME: makes this dynamic in the future so that permissionless listing is simpler diff --git a/packages/oraidex-server/src/polyfill.ts b/packages/oraidex-server/src/polyfill.ts index 741da1a5..5856cfbc 100644 --- a/packages/oraidex-server/src/polyfill.ts +++ b/packages/oraidex-server/src/polyfill.ts @@ -1,19 +1,20 @@ -import { Tendermint34Client } from "@cosmjs/tendermint-rpc"; +// import { Tendermint34Client } from "@cosmjs/tendermint-rpc"; +//@ts-ignore BigInt.prototype.toJSON = function () { return this.toString(); }; // polyfill -//@ts-ignore -Tendermint34Client.detectVersion = () => {}; -//@ts-ignore -Tendermint34Client.prototype.status = async function () { - return { - nodeInfo: { - network: "Oraichain", - version: "" - } - }; -}; +// //@ts-ignore +// Tendermint34Client.detectVersion = () => {}; +// //@ts-ignore +// Tendermint34Client.prototype.status = async function () { +// return { +// nodeInfo: { +// network: "Oraichain", +// version: "" +// } +// }; +// }; diff --git a/packages/oraidex-server/tests/polyfill-tendermint.spec.ts b/packages/oraidex-server/tests/polyfill-tendermint.spec.ts index 85512778..3dc7b68f 100644 --- a/packages/oraidex-server/tests/polyfill-tendermint.spec.ts +++ b/packages/oraidex-server/tests/polyfill-tendermint.spec.ts @@ -1,9 +1,9 @@ -import "../src/polyfill"; -import { Tendermint34Client } from "@cosmjs/tendermint-rpc"; +// import "../src/polyfill"; +// import { Tendermint34Client } from "@cosmjs/tendermint-rpc"; -describe("Polyfill tendermint 34", () => { - it("should polyfill tendermint", async () => { - const client = await Tendermint34Client.connect("https://rpc.orai.io"); - expect(client.status()).resolves.toStrictEqual({ nodeInfo: { network: "Oraichain", version: "" } }); - }); -}); +// describe("Polyfill tendermint 34", () => { +// it("should polyfill tendermint", async () => { +// const client = await Tendermint34Client.connect("https://rpc.orai.io"); +// expect(client.status()).resolves.toStrictEqual({ nodeInfo: { network: "Oraichain", version: "" } }); +// }); +// }); diff --git a/packages/oraidex-sync/src/pairs.ts b/packages/oraidex-sync/src/pairs.ts index 9b15321f..348c63ff 100644 --- a/packages/oraidex-sync/src/pairs.ts +++ b/packages/oraidex-sync/src/pairs.ts @@ -17,7 +17,7 @@ import { usdtCw20Address } from "./constants"; import { PairMapping } from "./types"; -import { WETH_CONTRACT, NEUTARO_ORAICHAIN_DENOM } from "@oraichain/oraidex-common/build/constant"; +import { WETH_CONTRACT, NEUTARO_ORAICHAIN_DENOM, BTC_CONTRACT } from "@oraichain/oraidex-common/build/constant"; import { pairLpTokens } from "@oraichain/oraidex-common/build/pairs"; // the orders are important! Do not change the order of the asset_infos. @@ -105,6 +105,11 @@ export const pairs: PairMapping[] = [ lp_token: pairLpTokens.ORAI_WETH, symbols: ["ORAI", "WETH"] }, + { + asset_infos: [{ native_token: { denom: ORAI } }, { token: { contract_addr: BTC_CONTRACT } }], + lp_token: pairLpTokens.ORAI_BTC, + symbols: ["ORAI", "BTC"] + }, { asset_infos: [{ native_token: { denom: NEUTARO_ORAICHAIN_DENOM } }, { token: { contract_addr: usdcCw20Address } }], lp_token: pairLpTokens.NTMPI_USDC, diff --git a/packages/oraidex-sync/src/pool-helper.ts b/packages/oraidex-sync/src/pool-helper.ts index 908c8ac3..bbc32e8c 100644 --- a/packages/oraidex-sync/src/pool-helper.ts +++ b/packages/oraidex-sync/src/pool-helper.ts @@ -81,10 +81,10 @@ export const isPoolHasFee = (assetInfos: [AssetInfo, AssetInfo]): boolean => { export const getPoolInfos = async (pairAddrs: string[], wantedHeight?: number): Promise => { // adjust the query height to get data from the past - const cosmwasmClient = await getCosmwasmClient(); - cosmwasmClient.setQueryClientWithHeight(wantedHeight); - const multicall = new MulticallQueryClient(cosmwasmClient, network.multicall); - const res = await queryPoolInfos(pairAddrs, multicall); + // const cosmwasmClient = await getCosmwasmClient(); + // cosmwasmClient.setQueryClientWithHeight(wantedHeight); + // const multicall = new MulticallQueryClient(cosmwasmClient, network.multicall); + const res = await queryPoolInfos(pairAddrs); return res; }; diff --git a/packages/oraidex-sync/src/query.ts b/packages/oraidex-sync/src/query.ts index cf6c372e..98292df9 100644 --- a/packages/oraidex-sync/src/query.ts +++ b/packages/oraidex-sync/src/query.ts @@ -17,20 +17,32 @@ import { generateSwapOperations, getCosmwasmClient, toDisplay } from "./helper"; import { pairs } from "./pairs"; import { parseAssetInfoOnlyDenom } from "./parse"; -async function queryPoolInfos(pairAddrs: string[], multicall: MulticallReadOnlyInterface): Promise { - // adjust the query height to get data from the past - const res = await multicall.tryAggregate({ - queries: pairAddrs.map((pair) => { - return { - address: pair, - data: toBinary({ - pool: {} - }) - }; - }) +async function queryPoolInfos(pairAddrs: string[]): Promise { + const calls: Call[] = pairAddrs.map((pair) => { + return { + address: pair, + data: toBinary({ + pool: {} + }) + }; }); - // reset query client to latest for other functions to call - return res.return_data.map((data) => (data.success ? fromBinary(data.data) : undefined)).filter((data) => data); // remove undefined items + + const chunks = []; + const MAX_CHUNK_SIZE = 10; + for (let i = 0; i < calls.length; i += MAX_CHUNK_SIZE) { + chunks.push(calls.slice(i, i + MAX_CHUNK_SIZE)); + } + + try { + const res = (await Promise.all(chunks.map(aggregateMulticall))) as any[][]; + return res + .flat() + .map((data) => (data.success ? fromBinary(data.data) : undefined)) + .filter((data) => data); + } catch (error) { + console.log(`Error when trying to queryPoolInfos: ${JSON.stringify(error)}`); + throw new Error("queryPoolInfosFails::" + error?.message); + } } async function queryAllPairInfos( @@ -99,7 +111,7 @@ async function simulateSwapPrice(pairPaths: AssetInfo[][], router: OraiswapRoute const res = (await Promise.all( chunks.map(aggregateMulticall) )) as OraiswapRouterTypes.SimulateSwapOperationsResponse[][]; - return res.flat().map((data, ind) => toDisplay(data.amount, dataCall[ind].sourceDecimals).toString()); + return res.flat().map((data, ind) => toDisplay(data?.amount || "0", dataCall[ind].sourceDecimals).toString()); } catch (error) { console.log(`Error when trying to simulate swap with pairs: ${JSON.stringify(pairPaths)} using router: ${error}`); throw new Error("SwapSimulateSwapPriceFail::" + error.message); // error case. Will be handled by the caller function diff --git a/packages/oraidex-sync/tests/helper.spec.ts b/packages/oraidex-sync/tests/helper.spec.ts index 14b3aab3..2e9be813 100644 --- a/packages/oraidex-sync/tests/helper.spec.ts +++ b/packages/oraidex-sync/tests/helper.spec.ts @@ -38,7 +38,7 @@ import * as poolHelper from "../src/pool-helper"; import * as helper from "../src/helper"; import * as parse from "../src/parse"; import { SwapOperation } from "@oraichain/oraidex-contracts-sdk/build/OraiswapRouter.types"; -import { NEUTARO_ORAICHAIN_DENOM, WETH_CONTRACT, pairLpTokens } from "@oraichain/oraidex-common"; +import { BTC_CONTRACT, NEUTARO_ORAICHAIN_DENOM, WETH_CONTRACT, pairLpTokens } from "@oraichain/oraidex-common"; describe("test-helper", () => { let duckDb: DuckDb; @@ -238,6 +238,11 @@ describe("test-helper", () => { lp_token: pairLpTokens.ORAI_WETH, symbols: ["ORAI", "WETH"] }, + { + asset_infos: [{ native_token: { denom: ORAI } }, { token: { contract_addr: BTC_CONTRACT } }], + lp_token: pairLpTokens.ORAI_BTC, + symbols: ["ORAI", "BTC"] + }, { asset_infos: [ { native_token: { denom: NEUTARO_ORAICHAIN_DENOM } }, From f54859da135faa55eef17e26027f5959777d4afe Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Sun, 18 Feb 2024 13:54:20 +0700 Subject: [PATCH 03/14] add pool ntmpi usdc --- .../tests/polyfill-tendermint.spec.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/oraidex-server/tests/polyfill-tendermint.spec.ts b/packages/oraidex-server/tests/polyfill-tendermint.spec.ts index 3dc7b68f..2d9fe3ff 100644 --- a/packages/oraidex-server/tests/polyfill-tendermint.spec.ts +++ b/packages/oraidex-server/tests/polyfill-tendermint.spec.ts @@ -1,9 +1,9 @@ -// import "../src/polyfill"; -// import { Tendermint34Client } from "@cosmjs/tendermint-rpc"; +import "../src/polyfill"; +import { Tendermint34Client } from "@cosmjs/tendermint-rpc"; -// describe("Polyfill tendermint 34", () => { -// it("should polyfill tendermint", async () => { -// const client = await Tendermint34Client.connect("https://rpc.orai.io"); -// expect(client.status()).resolves.toStrictEqual({ nodeInfo: { network: "Oraichain", version: "" } }); -// }); -// }); +describe("Polyfill tendermint 34", () => { + xit("should polyfill tendermint", async () => { + const client = await Tendermint34Client.connect("https://rpc.orai.io"); + expect(client.status()).resolves.toStrictEqual({ nodeInfo: { network: "Oraichain", version: "" } }); + }); +}); From 5c6f2da35ee55e68750b8cc8f82e19f2ffe6b228 Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Sun, 18 Feb 2024 18:09:12 +0700 Subject: [PATCH 04/14] fix import oraidex sync --- packages/oraidex-sync/src/pairs.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/oraidex-sync/src/pairs.ts b/packages/oraidex-sync/src/pairs.ts index 348c63ff..ef18d153 100644 --- a/packages/oraidex-sync/src/pairs.ts +++ b/packages/oraidex-sync/src/pairs.ts @@ -17,8 +17,8 @@ import { usdtCw20Address } from "./constants"; import { PairMapping } from "./types"; -import { WETH_CONTRACT, NEUTARO_ORAICHAIN_DENOM, BTC_CONTRACT } from "@oraichain/oraidex-common/build/constant"; -import { pairLpTokens } from "@oraichain/oraidex-common/build/pairs"; +import { WETH_CONTRACT, NEUTARO_ORAICHAIN_DENOM, BTC_CONTRACT } from "@oraichain/oraidex-common"; +import { pairLpTokens } from "@oraichain/oraidex-common"; // the orders are important! Do not change the order of the asset_infos. export const pairs: PairMapping[] = [ From bfbc34971161bfe8faffd89d0d86850615b6e21c Mon Sep 17 00:00:00 2001 From: Hau Nguyen Van Date: Sun, 18 Feb 2024 18:36:06 +0700 Subject: [PATCH 05/14] hardcode pool ntmpi usdc --- packages/oraidex-server/src/helper.ts | 4 +++- packages/oraidex-sync/src/constants.ts | 1 + packages/oraidex-sync/src/pairs.ts | 8 +++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/oraidex-server/src/helper.ts b/packages/oraidex-server/src/helper.ts index b4db40c6..53a703bb 100644 --- a/packages/oraidex-server/src/helper.ts +++ b/packages/oraidex-server/src/helper.ts @@ -30,6 +30,7 @@ import { import bech32 from "bech32"; import "dotenv/config"; import { DbQuery, LowHighPriceOfPairType } from "./db-query"; +import { pairLpTokens } from "@oraichain/oraidex-common"; const rpcUrl = process.env.RPC_URL || "https://rpc.orai.io"; const ORAI_INJ = "ORAI_INJ"; @@ -214,7 +215,8 @@ export const getAllPoolsInfo = async () => { } as PairInfoDataResponse; }); - return allPoolsInfo.filter(Boolean); + // TODO: ignore pool ORAI/BTC and pool undefined + return allPoolsInfo.filter((pools) => pools.liquidityAddr !== pairLpTokens.ORAI_BTC && pools); } catch (error) { console.log({ errorGetAllPoolsInfo: error }); } diff --git a/packages/oraidex-sync/src/constants.ts b/packages/oraidex-sync/src/constants.ts index e61f639b..3c82ed34 100644 --- a/packages/oraidex-sync/src/constants.ts +++ b/packages/oraidex-sync/src/constants.ts @@ -18,6 +18,7 @@ export const tronCw20Address = "orai1c7tpjenafvgjtgm9aqwm7afnke6c56hpdms8jc6md40 export const scOraiCw20Address = "orai1065qe48g7aemju045aeyprflytemx7kecxkf5m7u5h5mphd0qlcs47pclp"; export const usdcCw20Address = "orai15un8msx3n5zf9ahlxmfeqd2kwa5wm0nrpxer304m9nd5q6qq0g6sku5pdd"; export const atomIbcDenom = "ibc/A2E2EEC9057A4A1C2C0A6A4C78B0239118DF5F278830F50B4A6BDD7A66506B78"; +export const neutaroDenom = "ibc/576B1D63E401B6A9A071C78A1D1316D016EC9333D2FEB14AD503FAC4B8731CD1"; export const osmosisIbcDenom = "ibc/9C4DCD21B48231D0BC2AC3D1B74A864746B37E4292694C93C617324250D002FC"; export const injAddress = "orai19rtmkk6sn4tppvjmp5d5zj6gfsdykrl5rw2euu5gwur3luheuuusesqn49"; export const tenAmountInDecimalSix = 10000000; diff --git a/packages/oraidex-sync/src/pairs.ts b/packages/oraidex-sync/src/pairs.ts index ef18d153..da8de88d 100644 --- a/packages/oraidex-sync/src/pairs.ts +++ b/packages/oraidex-sync/src/pairs.ts @@ -5,6 +5,7 @@ import { ORAI, airiCw20Adress, atomIbcDenom, + neutaroDenom, injAddress, kwtCw20Address, milkyCw20Address, @@ -17,7 +18,7 @@ import { usdtCw20Address } from "./constants"; import { PairMapping } from "./types"; -import { WETH_CONTRACT, NEUTARO_ORAICHAIN_DENOM, BTC_CONTRACT } from "@oraichain/oraidex-common"; +import { WETH_CONTRACT, BTC_CONTRACT } from "@oraichain/oraidex-common"; import { pairLpTokens } from "@oraichain/oraidex-common"; // the orders are important! Do not change the order of the asset_infos. @@ -111,8 +112,9 @@ export const pairs: PairMapping[] = [ symbols: ["ORAI", "BTC"] }, { - asset_infos: [{ native_token: { denom: NEUTARO_ORAICHAIN_DENOM } }, { token: { contract_addr: usdcCw20Address } }], - lp_token: pairLpTokens.NTMPI_USDC, + asset_infos: [{ native_token: { denom: neutaroDenom } }, { token: { contract_addr: usdcCw20Address } }], + // lp_token: pairLpTokens.NTMPI_USDC, + lp_token: "orai1rmvjmwd940ztafxue7630g75px8tqma4jskjuu57fkj0eqahqfgqqwjm00", symbols: ["NTMPI", "USDC"] } ]; From d4beae15f42419eb7c193b6b9f756c5c1cf87f9c Mon Sep 17 00:00:00 2001 From: trungbach Date: Mon, 19 Feb 2024 09:58:49 +0700 Subject: [PATCH 06/14] chore: pumb oraidex-common latest --- packages/oraidex-sync/package.json | 2 +- packages/oraidex-sync/src/pairs.ts | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/oraidex-sync/package.json b/packages/oraidex-sync/package.json index 37cb3847..dc9c57e1 100644 --- a/packages/oraidex-sync/package.json +++ b/packages/oraidex-sync/package.json @@ -17,7 +17,7 @@ "@oraichain/cosmos-rpc-sync": "^1.0.7", "@oraichain/oraidex-contracts-sdk": "^1.0.24", "@oraichain/cw-simulate": "^2.8.72", - "@oraichain/oraidex-common": "^1.0.41", + "@oraichain/oraidex-common": "latest", "duckdb-async": "^0.9.2", "duckdb": "^0.9.2", "apache-arrow": "^12.0.1", diff --git a/packages/oraidex-sync/src/pairs.ts b/packages/oraidex-sync/src/pairs.ts index da8de88d..32d795b7 100644 --- a/packages/oraidex-sync/src/pairs.ts +++ b/packages/oraidex-sync/src/pairs.ts @@ -5,7 +5,6 @@ import { ORAI, airiCw20Adress, atomIbcDenom, - neutaroDenom, injAddress, kwtCw20Address, milkyCw20Address, @@ -18,8 +17,7 @@ import { usdtCw20Address } from "./constants"; import { PairMapping } from "./types"; -import { WETH_CONTRACT, BTC_CONTRACT } from "@oraichain/oraidex-common"; -import { pairLpTokens } from "@oraichain/oraidex-common"; +import { WETH_CONTRACT, BTC_CONTRACT, pairLpTokens, NEUTARO_ORAICHAIN_DENOM } from "@oraichain/oraidex-common"; // the orders are important! Do not change the order of the asset_infos. export const pairs: PairMapping[] = [ @@ -112,9 +110,8 @@ export const pairs: PairMapping[] = [ symbols: ["ORAI", "BTC"] }, { - asset_infos: [{ native_token: { denom: neutaroDenom } }, { token: { contract_addr: usdcCw20Address } }], - // lp_token: pairLpTokens.NTMPI_USDC, - lp_token: "orai1rmvjmwd940ztafxue7630g75px8tqma4jskjuu57fkj0eqahqfgqqwjm00", + asset_infos: [{ native_token: { denom: NEUTARO_ORAICHAIN_DENOM } }, { token: { contract_addr: usdcCw20Address } }], + lp_token: pairLpTokens.NTMPI_USDC, symbols: ["NTMPI", "USDC"] } ]; From f7fb7e6d9bfbbaa3b2fc7c1bb26828abded68181 Mon Sep 17 00:00:00 2001 From: trungbach Date: Mon, 19 Feb 2024 14:55:58 +0700 Subject: [PATCH 07/14] fix: handle contract data for pool --- packages/oraidex-sync/src/pool-helper.ts | 2 +- packages/oraidex-sync/src/query.ts | 12 +++++------- yarn.lock | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/oraidex-sync/src/pool-helper.ts b/packages/oraidex-sync/src/pool-helper.ts index bbc32e8c..df17708c 100644 --- a/packages/oraidex-sync/src/pool-helper.ts +++ b/packages/oraidex-sync/src/pool-helper.ts @@ -84,7 +84,7 @@ export const getPoolInfos = async (pairAddrs: string[], wantedHeight?: number): // const cosmwasmClient = await getCosmwasmClient(); // cosmwasmClient.setQueryClientWithHeight(wantedHeight); // const multicall = new MulticallQueryClient(cosmwasmClient, network.multicall); - const res = await queryPoolInfos(pairAddrs); + const res = await queryPoolInfos(pairAddrs, wantedHeight); return res; }; diff --git a/packages/oraidex-sync/src/query.ts b/packages/oraidex-sync/src/query.ts index 98292df9..cef9b521 100644 --- a/packages/oraidex-sync/src/query.ts +++ b/packages/oraidex-sync/src/query.ts @@ -17,7 +17,7 @@ import { generateSwapOperations, getCosmwasmClient, toDisplay } from "./helper"; import { pairs } from "./pairs"; import { parseAssetInfoOnlyDenom } from "./parse"; -async function queryPoolInfos(pairAddrs: string[]): Promise { +async function queryPoolInfos(pairAddrs: string[], wantedHeight?: number): Promise { const calls: Call[] = pairAddrs.map((pair) => { return { address: pair, @@ -34,11 +34,8 @@ async function queryPoolInfos(pairAddrs: string[]): Promise { } try { - const res = (await Promise.all(chunks.map(aggregateMulticall))) as any[][]; - return res - .flat() - .map((data) => (data.success ? fromBinary(data.data) : undefined)) - .filter((data) => data); + const res = (await Promise.all(chunks.map((chunk) => aggregateMulticall(chunk, wantedHeight)))) as any[][]; + return res.flat().filter(Boolean); } catch (error) { console.log(`Error when trying to queryPoolInfos: ${JSON.stringify(error)}`); throw new Error("queryPoolInfosFails::" + error?.message); @@ -118,8 +115,9 @@ async function simulateSwapPrice(pairPaths: AssetInfo[][], router: OraiswapRoute } } -async function aggregateMulticall(queries: Call[]): Promise { +async function aggregateMulticall(queries: Call[], wantedHeight?: number): Promise { const client = await getCosmwasmClient(); + client.setQueryClientWithHeight(wantedHeight); const multicall = new MulticallQueryClient(client, network.multicall); const res = await multicall.tryAggregate({ queries }); return res.return_data.map((data) => (data.success ? fromBinary(data.data) : undefined)) as T[]; diff --git a/yarn.lock b/yarn.lock index 1aaca31a..763065cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3363,6 +3363,24 @@ resolved "https://registry.yarnpkg.com/@oraichain/immutable/-/immutable-4.3.9.tgz#ff8d5a7b39b5b01f3f72a902cffbfea32ccb20c3" integrity sha512-INpHnhL970OCkR7I71Kssb2aLl2l4Y/x8W6FlyRO0KmC8GHjxc/hlNB1t44BiI7lkOYmcWMRQoC8dwParsp1RQ== +"@oraichain/oraidex-common@latest": + version "1.0.67" + resolved "https://registry.yarnpkg.com/@oraichain/oraidex-common/-/oraidex-common-1.0.67.tgz#b16221be2b70ecb118e76462306dd643b16fdc71" + integrity sha512-4Jj4gPZJeRSm9z3PAk8+Q8lUZ8miFPAodqooct5MaqgtJloblpJkDr0/BGZYg2783nUcd7U7Ku95vsSMUhlewg== + dependencies: + "@cosmjs/amino" "^0.31.0" + "@cosmjs/cosmwasm-stargate" "^0.31.0" + "@cosmjs/crypto" "^0.31.0" + "@cosmjs/proto-signing" "^0.31.0" + "@cosmjs/stargate" "^0.31.0" + "@cosmjs/tendermint-rpc" "0.31.0" + "@ethersproject/providers" "^5.0.10" + "@keplr-wallet/types" "^0.11.38" + "@oraichain/oraidex-contracts-sdk" "^1.0.30" + bignumber.js "^9.0.1" + cosmjs-types "^0.8.0" + ethers "^5.0.15" + "@oraichain/oraidex-universal-swap@1.0.14": version "1.0.14" resolved "https://registry.yarnpkg.com/@oraichain/oraidex-universal-swap/-/oraidex-universal-swap-1.0.14.tgz#fd4b60e7cfc21984dbaa14a7b9a2c560f02da37d" From 36457a394bb121e2f5b5a7e9b84e141ee74e1965 Mon Sep 17 00:00:00 2001 From: trungbach Date: Mon, 19 Feb 2024 16:07:15 +0700 Subject: [PATCH 08/14] chore: ignore orai/btc pool --- packages/oraidex-server/src/helper.ts | 2 +- packages/oraidex-sync/src/index.ts | 1 + packages/oraidex-sync/src/pool-helper.ts | 1 + packages/oraidex-sync/src/query.ts | 4 +++- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/oraidex-server/src/helper.ts b/packages/oraidex-server/src/helper.ts index 53a703bb..cf2fe22a 100644 --- a/packages/oraidex-server/src/helper.ts +++ b/packages/oraidex-server/src/helper.ts @@ -216,7 +216,7 @@ export const getAllPoolsInfo = async () => { }); // TODO: ignore pool ORAI/BTC and pool undefined - return allPoolsInfo.filter((pools) => pools.liquidityAddr !== pairLpTokens.ORAI_BTC && pools); + return allPoolsInfo.filter((pools) => pools && pools.liquidityAddr !== pairLpTokens.ORAI_BTC); } catch (error) { console.log({ errorGetAllPoolsInfo: error }); } diff --git a/packages/oraidex-sync/src/index.ts b/packages/oraidex-sync/src/index.ts index 5ffc6dfb..466fe337 100644 --- a/packages/oraidex-sync/src/index.ts +++ b/packages/oraidex-sync/src/index.ts @@ -108,6 +108,7 @@ class OraiDexSync { pairInfos.map((pair) => pair.pairAddr), currentHeight ); + console.dir({ poolInfos }, { depth: null }); const INITIAL_TIMESTAMP = 1; await this.duckDb.insertPoolAmountHistory( // we check if poolInfos[index] is available because in currentHeight we query, maybe it has some pools are not created yet diff --git a/packages/oraidex-sync/src/pool-helper.ts b/packages/oraidex-sync/src/pool-helper.ts index df17708c..21ec1b93 100644 --- a/packages/oraidex-sync/src/pool-helper.ts +++ b/packages/oraidex-sync/src/pool-helper.ts @@ -357,6 +357,7 @@ export const getPoolAmounts = async (pools: PairInfoData[]): Promise { + console.dir({ pairAddrs }, { depth: null }); const calls: Call[] = pairAddrs.map((pair) => { return { address: pair, @@ -34,7 +35,8 @@ async function queryPoolInfos(pairAddrs: string[], wantedHeight?: number): Promi } try { - const res = (await Promise.all(chunks.map((chunk) => aggregateMulticall(chunk, wantedHeight)))) as any[][]; + const res = (await Promise.all(chunks.map((chunk) => aggregateMulticall(chunk)))) as any[][]; + console.dir({ res }, { depth: null }); return res.flat().filter(Boolean); } catch (error) { console.log(`Error when trying to queryPoolInfos: ${JSON.stringify(error)}`); From 7c8dd7a8c1026b1b7f7745580c5a28608a9b3697 Mon Sep 17 00:00:00 2001 From: trungbach Date: Mon, 19 Feb 2024 16:32:13 +0700 Subject: [PATCH 09/14] chore: fix neutaro denom --- packages/oraidex-common/src/pairs.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/oraidex-common/src/pairs.ts b/packages/oraidex-common/src/pairs.ts index 063511f8..aa73b535 100644 --- a/packages/oraidex-common/src/pairs.ts +++ b/packages/oraidex-common/src/pairs.ts @@ -14,8 +14,8 @@ import { TRX_CONTRACT, USDC_CONTRACT, USDT_CONTRACT, + NEUTARO_ORAICHAIN_DENOM, WETH_CONTRACT, - NEUTARO_ORAICHAIN_DENOM } from "./constant"; import { parseAssetInfo } from "./helper"; import { TokenItemType, assetInfoMap } from "./token"; @@ -91,9 +91,9 @@ export const PAIRS: PairMapping[] = [ { asset_infos: [{ native_token: { denom: ORAI } }, { token: { contract_addr: WETH_CONTRACT } }], symbols: ["ORAI", "WETH"] - }, + },, + asset_infos: [{ native_token: { denom: NEUTARO_ORAICHAIN_DENOM } }, { token: { contract_addr: USDC_CONTRACT } }], { - asset_infos: [{ native_token: { denom: NEUTARO_ORAICHAIN_DENOM } }, { token: { contract_addr: USDC_CONTRACT } }], symbols: ["NTMPI", "USDC"] }, { From 78addb8c27dbae3789afb8bba0e71b1b90148da1 Mon Sep 17 00:00:00 2001 From: trungbach Date: Mon, 19 Feb 2024 16:33:15 +0700 Subject: [PATCH 10/14] chore: fix neutaro denom --- packages/oraidex-common/src/pairs.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/oraidex-common/src/pairs.ts b/packages/oraidex-common/src/pairs.ts index aa73b535..063511f8 100644 --- a/packages/oraidex-common/src/pairs.ts +++ b/packages/oraidex-common/src/pairs.ts @@ -14,8 +14,8 @@ import { TRX_CONTRACT, USDC_CONTRACT, USDT_CONTRACT, - NEUTARO_ORAICHAIN_DENOM, WETH_CONTRACT, + NEUTARO_ORAICHAIN_DENOM } from "./constant"; import { parseAssetInfo } from "./helper"; import { TokenItemType, assetInfoMap } from "./token"; @@ -91,9 +91,9 @@ export const PAIRS: PairMapping[] = [ { asset_infos: [{ native_token: { denom: ORAI } }, { token: { contract_addr: WETH_CONTRACT } }], symbols: ["ORAI", "WETH"] - },, - asset_infos: [{ native_token: { denom: NEUTARO_ORAICHAIN_DENOM } }, { token: { contract_addr: USDC_CONTRACT } }], + }, { + asset_infos: [{ native_token: { denom: NEUTARO_ORAICHAIN_DENOM } }, { token: { contract_addr: USDC_CONTRACT } }], symbols: ["NTMPI", "USDC"] }, { From 37416ac49a79d0e38b667362d59d9759e8ee2de3 Mon Sep 17 00:00:00 2001 From: trungbach Date: Mon, 19 Feb 2024 16:41:02 +0700 Subject: [PATCH 11/14] chore: fix neutaro denom --- packages/oraidex-common/src/pairs.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/oraidex-common/src/pairs.ts b/packages/oraidex-common/src/pairs.ts index 063511f8..8640a8ea 100644 --- a/packages/oraidex-common/src/pairs.ts +++ b/packages/oraidex-common/src/pairs.ts @@ -14,8 +14,8 @@ import { TRX_CONTRACT, USDC_CONTRACT, USDT_CONTRACT, - WETH_CONTRACT, - NEUTARO_ORAICHAIN_DENOM + WETH_CONTRACT + // NEUTARO_ORAICHAIN_DENOM } from "./constant"; import { parseAssetInfo } from "./helper"; import { TokenItemType, assetInfoMap } from "./token"; @@ -93,7 +93,10 @@ export const PAIRS: PairMapping[] = [ symbols: ["ORAI", "WETH"] }, { - asset_infos: [{ native_token: { denom: NEUTARO_ORAICHAIN_DENOM } }, { token: { contract_addr: USDC_CONTRACT } }], + asset_infos: [ + { native_token: { denom: "ibc/576B1D63E401B6A9A071C78A1D1316D016EC9333D2FEB14AD503FAC4B8731CD1" } }, + { token: { contract_addr: USDC_CONTRACT } } + ], symbols: ["NTMPI", "USDC"] }, { From 9d41aeeaa35ae5b6ae7234f95369a01abf7463c3 Mon Sep 17 00:00:00 2001 From: trungbach Date: Mon, 19 Feb 2024 16:44:22 +0700 Subject: [PATCH 12/14] chore: fix neutaro denom --- packages/oraidex-common/src/pairs.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/oraidex-common/src/pairs.ts b/packages/oraidex-common/src/pairs.ts index 8640a8ea..17d8a3f6 100644 --- a/packages/oraidex-common/src/pairs.ts +++ b/packages/oraidex-common/src/pairs.ts @@ -14,8 +14,8 @@ import { TRX_CONTRACT, USDC_CONTRACT, USDT_CONTRACT, - WETH_CONTRACT - // NEUTARO_ORAICHAIN_DENOM + WETH_CONTRACT, + NEUTARO_ORAICHAIN_DENOM } from "./constant"; import { parseAssetInfo } from "./helper"; import { TokenItemType, assetInfoMap } from "./token"; From fd10f9feedc81340f4d070ee7d9de0948ed8ecf1 Mon Sep 17 00:00:00 2001 From: trungbach Date: Mon, 19 Feb 2024 16:51:59 +0700 Subject: [PATCH 13/14] chore: fix neutaro denom --- packages/oraidex-common/src/pairs.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/oraidex-common/src/pairs.ts b/packages/oraidex-common/src/pairs.ts index 17d8a3f6..3efb2c00 100644 --- a/packages/oraidex-common/src/pairs.ts +++ b/packages/oraidex-common/src/pairs.ts @@ -15,7 +15,7 @@ import { USDC_CONTRACT, USDT_CONTRACT, WETH_CONTRACT, - NEUTARO_ORAICHAIN_DENOM + NEUTARO_ORAICHAIN_DENOM as NEUTARO_ADDRESS } from "./constant"; import { parseAssetInfo } from "./helper"; import { TokenItemType, assetInfoMap } from "./token"; @@ -93,10 +93,7 @@ export const PAIRS: PairMapping[] = [ symbols: ["ORAI", "WETH"] }, { - asset_infos: [ - { native_token: { denom: "ibc/576B1D63E401B6A9A071C78A1D1316D016EC9333D2FEB14AD503FAC4B8731CD1" } }, - { token: { contract_addr: USDC_CONTRACT } } - ], + asset_infos: [{ native_token: { denom: NEUTARO_ADDRESS } }, { token: { contract_addr: USDC_CONTRACT } }], symbols: ["NTMPI", "USDC"] }, { From 078c2c588b7a68d52323746c688e3cbb463342f3 Mon Sep 17 00:00:00 2001 From: trungbach Date: Tue, 20 Feb 2024 11:21:05 +0700 Subject: [PATCH 14/14] refactor: remove redundant code --- .eslintrc.json | 4 ++-- packages/oraidex-sync/src/index.ts | 1 - packages/oraidex-sync/src/pool-helper.ts | 1 - packages/oraidex-sync/src/query.ts | 4 +--- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 017fb198..a947433f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -33,8 +33,8 @@ "rules": { "@typescript-eslint/no-explicit-any": ["warn"], "@typescript-eslint/no-unused-vars": "warn", - "security/detect-object-injection": "off" - // "@typescript-eslint/ban-ts-comment": "off" + "security/detect-object-injection": "off", + "@typescript-eslint/ban-ts-comment": "off" } }, { diff --git a/packages/oraidex-sync/src/index.ts b/packages/oraidex-sync/src/index.ts index 466fe337..5ffc6dfb 100644 --- a/packages/oraidex-sync/src/index.ts +++ b/packages/oraidex-sync/src/index.ts @@ -108,7 +108,6 @@ class OraiDexSync { pairInfos.map((pair) => pair.pairAddr), currentHeight ); - console.dir({ poolInfos }, { depth: null }); const INITIAL_TIMESTAMP = 1; await this.duckDb.insertPoolAmountHistory( // we check if poolInfos[index] is available because in currentHeight we query, maybe it has some pools are not created yet diff --git a/packages/oraidex-sync/src/pool-helper.ts b/packages/oraidex-sync/src/pool-helper.ts index 21ec1b93..df17708c 100644 --- a/packages/oraidex-sync/src/pool-helper.ts +++ b/packages/oraidex-sync/src/pool-helper.ts @@ -357,7 +357,6 @@ export const getPoolAmounts = async (pools: PairInfoData[]): Promise { - console.dir({ pairAddrs }, { depth: null }); const calls: Call[] = pairAddrs.map((pair) => { return { address: pair, @@ -35,8 +34,7 @@ async function queryPoolInfos(pairAddrs: string[], wantedHeight?: number): Promi } try { - const res = (await Promise.all(chunks.map((chunk) => aggregateMulticall(chunk)))) as any[][]; - console.dir({ res }, { depth: null }); + const res = (await Promise.all(chunks.map((chunk) => aggregateMulticall(chunk, wantedHeight)))) as any[][]; return res.flat().filter(Boolean); } catch (error) { console.log(`Error when trying to queryPoolInfos: ${JSON.stringify(error)}`);