diff --git a/.env.example b/.env.example index c74f71f..6b88805 100644 --- a/.env.example +++ b/.env.example @@ -6,7 +6,9 @@ MERCURY_BACKEND_ENDPOINT_MAINNET=https://mainnet.mercurydata.app MERCURY_GRAPHQL_ENDPOINT_MAINNET=https://mainnet.mercurydata.app #Mercury TESTNET + MERCURY_API_KEY_TESTNET= MERCURY_BACKEND_ENDPOINT_TESTNET=https://api.mercurydata.app MERCURY_GRAPHQL_ENDPOINT_TESTNET=https://api.mercurydata.app + diff --git a/src/utils/info/pools/index.ts b/src/utils/info/pools/index.ts index 41d69a3..3e91e90 100644 --- a/src/utils/info/pools/index.ts +++ b/src/utils/info/pools/index.ts @@ -30,6 +30,7 @@ export const stellarNetworkDict = { }; export const buildPoolsInfo = async ( + data: MercuryPair[], tokenList: TokenType[], network: Network @@ -142,6 +143,7 @@ export const buildPoolsInfo = async ( return result }; + export const getDate = (timestamp: string) => { return new Date(parseInt(timestamp) * 1000).toISOString().split("T")[0]; }; @@ -263,41 +265,29 @@ export const getPoolFees = ( export const getPoolVolumeChartData = (events: MercuryEvent[], pool: Pool) => { const poolEvents = events.filter((e) => { - if ( - e.tokenA === pool?.tokenA.contract && - e.tokenB === pool?.tokenB.contract - ) { - return true; - } - - if ( - e.tokenA === pool?.tokenB.contract && - e.tokenB === pool?.tokenA.contract - ) { - return true; - } - - return false; + return ( + e.eType === "swap" && + ( + (e.tokenA === pool?.tokenA.contract && e.tokenB === pool?.tokenB.contract) || + (e.tokenA === pool?.tokenB.contract && e.tokenB === pool?.tokenA.contract) + ) + ); }); - const poolsEventsWithTokensOrdered = poolEvents.map((e) => { - if ( - e.tokenA === pool?.tokenA.contract && - e.tokenB === pool?.tokenB.contract - ) { - return e; + const orderedPoolEvents = poolEvents.map((e) => { + if (e.tokenA === pool?.tokenB.contract && e.tokenB === pool?.tokenA.contract) { + return { + ...e, + tokenA: e.tokenB, + tokenB: e.tokenA, + amountA: e.amountB, + amountB: e.amountA, + }; } - - return { - ...e, - tokenA: e.tokenB, - tokenB: e.tokenA, - amountA: e.amountB, - amountB: e.amountA, - }; + return e; }); - const volumeChartData = poolsEventsWithTokensOrdered.map((e) => { + const volumeChartData = orderedPoolEvents.map((e) => { const volumes = getPoolVolume( e.amountA, e.amountB, @@ -306,6 +296,7 @@ export const getPoolVolumeChartData = (events: MercuryEvent[], pool: Pool) => { pool?.tokenA.decimals, pool?.tokenB.decimals ); + return { timestamp: e.timestamp, date: getDate(e.timestamp), @@ -320,6 +311,7 @@ export const getPoolVolumeChartData = (events: MercuryEvent[], pool: Pool) => { return filledVolumeChartData as VolumeChartData[]; }; + export const getPoolFeesChartData = (events: MercuryEvent[], pool: Pool) => { const poolEvents = events.filter((e) => { if ( diff --git a/src/zephyr/helpers.ts b/src/zephyr/helpers.ts index 2df3b30..c27c11a 100644 --- a/src/zephyr/helpers.ts +++ b/src/zephyr/helpers.ts @@ -19,12 +19,16 @@ export const parseMercuryScvalResponse = (data: any) => { for (let key in d) { const value = parseScvalValue(d[key]); + if (typeof value === "bigint" || typeof value === "number") { n[key] = value.toString(); - } else if( key == 'txHash'){ + } else if(key == 'txHash'){ const txHash = StellarSdk.xdr.Hash.fromXDR(value, 'hex').toString('hex') - if(txHash.length != 64)throw new Error('Invalid txHash length'); + if(txHash.length != 64) throw new Error('Invalid txHash length'); n[key] = txHash; + } else if(key == 'eType') { + const eventType = String(value).toLowerCase(); + n[key] = eventType; } else { n[key] = value; } @@ -59,8 +63,6 @@ export const getMercuryPhoenixPools = async (network: Network) => { request: GET_ALL_PAIRS(phoenix_pairs), }); - console.log(response); - if (!response.ok) { return []; } @@ -79,8 +81,6 @@ export const getMercuryAquaPools = async (network: Network) => { request: GET_ALL_PAIRS(aqua_pairs), }); - console.log(response); - if (!response.ok) { return []; } @@ -120,6 +120,7 @@ export const getMercuryRsvCh = async (network: Network) => { export const getMercuryEvents = async (network: Network) => { const mercuryInstance = getMercuryInstance(network); const { soroswap_events } = await fetchZephyrTables({ network }); + const response = await mercuryInstance.getCustomQuery({ request: GET_ALL_EVENTS(soroswap_events), }); diff --git a/tsconfig.json b/tsconfig.json index cf4ee35..60e779a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es5", + "target": "es2015", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true,