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.
Add Grizzly Trade Derivatives V2 dimensions adapters.
- Loading branch information
Showing
2 changed files
with
129 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import request, { gql } from "graphql-request"; | ||
import { FetchResultVolume, SimpleAdapter } from "../../adapters/types"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
import { getTimestampAtStartOfDayUTC } from "../../utils/date"; | ||
|
||
const grizzlyPerpsV2Subgraph = | ||
"https://api.studio.thegraph.com/query/55804/bnb-trade/version/latest"; | ||
|
||
interface IReferralRecord { | ||
volume: string; // Assuming volume is a string that represents a number | ||
timestamp: number; | ||
} | ||
|
||
interface IVolumeStat { | ||
cumulativeVolumeUsd: string; | ||
volumeUsd: string; | ||
id: string; | ||
} | ||
|
||
const fetch = () => { | ||
return async (timestamp: number): Promise<FetchResultVolume> => { | ||
const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp); | ||
|
||
const graphQuery = gql` | ||
query MyQuery { | ||
volumeStats(where: {timestamp: ${todaysTimestamp}, period: "daily"}) { | ||
cumulativeVolumeUsd | ||
id | ||
volumeUsd | ||
} | ||
} | ||
`; | ||
|
||
const response = await request(grizzlyPerpsV2Subgraph, graphQuery); | ||
const volumeStats: IVolumeStat[] = response.volumeStats; | ||
|
||
let dailyVolumeUSD = BigInt(0); | ||
|
||
volumeStats.forEach((vol) => { | ||
dailyVolumeUSD += BigInt(vol.volumeUsd); | ||
}); | ||
|
||
const finalDailyVolume = parseInt(dailyVolumeUSD.toString()) / 1e18; | ||
|
||
return { | ||
dailyVolume: finalDailyVolume.toString(), | ||
timestamp: todaysTimestamp, | ||
}; | ||
}; | ||
}; | ||
|
||
const methodology = { | ||
dailyVolume: | ||
"Total cumulativeVolumeUsd for specified chain for the given day", | ||
}; | ||
|
||
const adapter: SimpleAdapter = { | ||
adapter: { | ||
[CHAIN.BSC]: { | ||
fetch: fetch(), | ||
start: async () => 1706832000, | ||
meta: { | ||
methodology, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default adapter; |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Chain } from "@defillama/sdk/build/general"; | ||
import { gql, request } from "graphql-request"; | ||
import type { ChainEndpoints } from "../adapters/types"; | ||
import { Adapter } from "../adapters/types"; | ||
import { CHAIN } from "../helpers/chains"; | ||
|
||
import { getTimestampAtStartOfDayUTC } from "../utils/date"; | ||
|
||
const endpoints = { | ||
[CHAIN.BSC]: | ||
"https://api.studio.thegraph.com/query/55804/bnb-trade/version/latest", | ||
}; | ||
|
||
const graphs = (graphUrls: ChainEndpoints) => { | ||
return (chain: Chain) => { | ||
return async (timestamp: number) => { | ||
const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp); | ||
const period = "daily"; | ||
|
||
const graphQuery = gql`{ | ||
feeStats(where: {timestamp: ${todaysTimestamp}, period: "${period}"}) { | ||
id | ||
timestamp | ||
period | ||
cumulativeFee | ||
cumulativeFeeUsd | ||
feeUsd | ||
} | ||
}`; | ||
|
||
const graphRes = await request(graphUrls[chain], graphQuery); | ||
|
||
const dailyFee = parseInt(graphRes.feeStats[0].feeUsd); | ||
|
||
const finalDailyFee = dailyFee / 1e18; | ||
const totalFees = parseInt(graphRes.feeStats[0].cumulativeFeeUsd) / 1e18; | ||
|
||
return { | ||
timestamp, | ||
dailyFees: finalDailyFee.toString(), | ||
totalFees: totalFees.toString(), | ||
//dailyRevenue: (finalDailyFee * 0.3).toString(), | ||
}; | ||
}; | ||
}; | ||
}; | ||
|
||
const adapter: Adapter = { | ||
adapter: { | ||
[CHAIN.BSC]: { | ||
fetch: graphs(endpoints)(CHAIN.BSC), | ||
start: async () => 1706832000, | ||
meta: { | ||
methodology: "All treasury, pool and keeper fees are collected", | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default adapter; |