forked from DefiLlama/dimension-adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
14 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |