Skip to content

Commit

Permalink
fix vapordex
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmkeng committed Dec 8, 2022
1 parent a780988 commit 39dbf9d
Showing 1 changed file with 14 additions and 73 deletions.
87 changes: 14 additions & 73 deletions dexs/vapordex/index.ts
Original file line number Diff line number Diff line change
@@ -1,74 +1,15 @@
import { gql, GraphQLClient } from "graphql-request";
import { CHAIN } from "../../helpers/chains";

const graphQLClient = new GraphQLClient(
"https://api.thegraph.com/subgraphs/name/mejiasd3v/vapordex-avalanche"
);

const getGQLClient = () => {
return graphQLClient;
};

const getData = () => {
return gql`
query data {
dexAmmProtocols {
cumulativeVolumeUSD
}
financialsDailySnapshots {
dailyVolumeUSD
timestamp
}
}
`;
};

const methodology = {
timeStamp: "Timestamp",
dailyVolume: "Daily volume on the dex",
totalVolume: "Total volume in USD",
};

const fetch = async () => {
const response = await getGQLClient().request(getData());

// Cumulative volume in USD
const cumulativeVolumeUSD = Math.round(
response.dexAmmProtocols[0].cumulativeVolumeUSD
);

// Calculating the total length of daily snapshots to determine the latest one
const responseLength = response.financialsDailySnapshots.length;

// Daily volume in USD
const latestDailyVolumeUSD = Math.round(
response.financialsDailySnapshots[responseLength - 1].dailyVolumeUSD
);

// Timestamp of the latest daily volume
const timeStamp =
response.financialsDailySnapshots[responseLength - 1].timestamp;

return {
timeStamp: timeStamp,
dailyVolume: `${latestDailyVolumeUSD}`,
totalVolume: `${cumulativeVolumeUSD}`,
};
};

const adapter = {
adapter: {
[CHAIN.AVAX]: {
fetch: fetch,
runAtCurrTime: true,
start: async () => 0,
meta: {
methodology,
},
},
},
};

export default adapter;

// Test - yarn test dexs vapordex
import { univ2Adapter } from "../../helpers/getUniSubgraphVolume";

const adapters = univ2Adapter({
[CHAIN.AVAX]: "https://api.thegraph.com/subgraphs/name/mejiasd3v/vapordex-avalanche"
}, {
factoriesName: "dexAmmProtocols",
totalVolume: "cumulativeVolumeUSD",
dayData: "financialsDailySnapshot",
dailyVolume: "dailyVolumeUSD",
dailyVolumeTimestampField: "timestamp"
});

adapters.adapter.avax.start = async () => 1663545600;
export default adapters;

0 comments on commit 39dbf9d

Please sign in to comment.