Important considerations
The timestamp passed to fetch function is the end of the 24 hour period, for which the data should be provided. Therefore your adapter should return data for the 24 hours leading up to this timestamp
Correct:
async (timestamp, block) => {
const from = timestamp - ONE_DAY_IN_SECONDS // 60*60*24
const to = timestamp
...
}
Wrong:
async (timestamp, block) => {
const from = timestamp
const to = timestamp + ONE_DAY_IN_SECONDS //wrong!
...
}
- If you want to list your protocol in different dashboards you can return in the same adapters dimensions of different dashboards. See the following example:
const adapter = {
adapter: {
...,
fetch: async (timestamp, block) => {
const { dailyVolume } = await querySubgraph(volumeQuery, timestamp)
const { dailyFees } = await querySubgraph(feesQuery, timestamp)
return {
dailyVolume, // dimension for dexs dashboard
dailyFees, // dimension for fees dashboard
}
}
...,
}
}
- In case you wanna list your protocol in different dashboards which share same dimension, for example dexs dashboard (for swaps) and derivatives dashboard (for margin trading) you can use a
BreakdownAdapter
.
// dummy example
const adapter: BreakdownAdapter = {
breakdown: {
"swap": {
fetch: async () => ({ dailyVolume: "32498" })
},
"margin": {
fetch: async () => ({ dailyVolume: "874562" })
}
}
}
- For fees and revenue adapters please don' forget to include how have you calculated the values in the methodology attribute.
const adapter = {
adapter: {
...
fetch: async () => ({
dailyFees: "32498",
dailyRevenue: "0",
dailySupplySideRevenue: "32498"
}),
meta: {
methodology: {
Fees: "User pays 2% of each swap",
Revenue: "Protocol takes no revenue",
SupplySideRevenue: "LPs revenue is 2% of user fees",
}
}
}
}
- If the adapter is not able to provide data for all dimensions, let's say for example you can only provide data for
dailyVolume
but not fortotalVolume
, please keep the dimension asundefined
, don't assign an arbitrary value or set to it"0"
.
// wrong
{
dailyFees: "2144",
totalFees: "0" // <- wrong!!
}
// correct
{
dailyFees: "2144"
}
- If the adapter can't be used to backfill data and only allows to get data for today's timestamp, please set the flag
runAtCurrTime
totrue
. See more about this flag in the previous sections.
const adapter = {
adapter: {
fetch: fetchFunction,
runAtCurrTime: true
}
}
Please, consider using the BigNumber library when doing mathematical operations that might result or include a value with a magnitude outside the range of safe values to use in JavaScript.
const feesInGas = new BigNumber(graphRes["fees"])
const ethGasPrice = await getGasPrice(timestamp)
return {
dailyRevenue = feesInGas.multiplyBy(ethGasPrice)
}
Last modified 4mo ago