Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add filter eType='swap' #98

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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


52 changes: 22 additions & 30 deletions src/utils/info/pools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const stellarNetworkDict = {
};

export const buildPoolsInfo = async (

data: MercuryPair[],
tokenList: TokenType[],
network: Network
Expand Down Expand Up @@ -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];
};
Expand Down Expand Up @@ -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,
Expand All @@ -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),
Expand All @@ -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 (
Expand Down
13 changes: 7 additions & 6 deletions src/zephyr/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -59,8 +63,6 @@ export const getMercuryPhoenixPools = async (network: Network) => {
request: GET_ALL_PAIRS(phoenix_pairs),
});

console.log(response);

if (!response.ok) {
return [];
}
Expand All @@ -79,8 +81,6 @@ export const getMercuryAquaPools = async (network: Network) => {
request: GET_ALL_PAIRS(aqua_pairs),
});

console.log(response);

if (!response.ok) {
return [];
}
Expand Down Expand Up @@ -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),
});
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es2015",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
Expand Down