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
3 changed files
with
91 additions
and
2 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
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,27 @@ | ||
import { Adapter, FetchResultFees } from '../../adapters/types'; | ||
import { ZKSYNC } from '../../helpers/chains'; | ||
import { fetchV1 } from './koi-finance'; | ||
|
||
|
||
const getFees = async (timestamp: number): Promise<FetchResultFees> => { | ||
const [feeV1] = await Promise.all([fetchV1()(timestamp)]); | ||
const dailyFees = Number(feeV1.dailyFees); | ||
const dailyRevenue = Number(feeV1.dailyRevenue); | ||
|
||
return { | ||
dailyFees: `${dailyFees}`, | ||
dailyRevenue: `${dailyRevenue}`, | ||
timestamp | ||
} | ||
} | ||
|
||
const adapter: Adapter = { | ||
adapter: { | ||
[ZKSYNC]: { | ||
fetch: getFees, | ||
start: 1677110400, // TODO: Add accurate timestamp | ||
}, | ||
}, | ||
}; | ||
|
||
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,62 @@ | ||
import request, { gql } from "graphql-request"; | ||
import { getBlock } from "../../helpers/getBlock"; | ||
import { | ||
getTimestampAtStartOfDayUTC, | ||
getTimestampAtStartOfPreviousDayUTC | ||
} from "../../utils/date"; | ||
import BigNumber from "bignumber.js"; | ||
|
||
const endpoint = "https://api.goldsky.com/api/public/project_clmtie4nnezuh2nw6hhjg6mo7/subgraphs/mute_switch/v0.0.7/gn" | ||
|
||
export const fetchV1 = () => { | ||
return async (timestamp: number) => { | ||
const todaysTimestamp = getTimestampAtStartOfDayUTC(timestamp); | ||
const yesterdaysTimestamp = getTimestampAtStartOfPreviousDayUTC(timestamp); | ||
const todaysBlock = await getBlock( | ||
todaysTimestamp, | ||
"era", | ||
{} | ||
); | ||
|
||
const yesterdaysBlock = await getBlock(yesterdaysTimestamp, "era", {}); | ||
|
||
const query = gql` | ||
query fees { | ||
yesterday: pairs(block: {number: ${yesterdaysBlock}}, where: {volumeUSD_gt: "0"}, first: 1000, orderBy:volumeUSD, orderDirection:desc) { | ||
id | ||
stable | ||
pairFee | ||
volumeUSD | ||
} | ||
today: pairs(block: {number: ${todaysBlock}}, where: {volumeUSD_gt: "0"}, first: 1000, orderBy:volumeUSD, orderDirection:desc) { | ||
id | ||
stable | ||
pairFee | ||
volumeUSD | ||
} | ||
} | ||
`; | ||
const todayVolume: { [id: string]: BigNumber } = {}; | ||
const graphRes = await request(endpoint, query); | ||
let dailyFee = new BigNumber(0); | ||
for (const pool of graphRes["today"]) { | ||
todayVolume[pool.id] = new BigNumber(pool.volumeUSD); | ||
} | ||
|
||
for (const pool of graphRes["yesterday"]) { | ||
if (!todayVolume[pool.id]) continue; | ||
|
||
const dailyVolume = BigNumber(todayVolume[pool.id]).minus( | ||
pool.volumeUSD | ||
); | ||
|
||
dailyFee = dailyFee.plus(dailyVolume.times(pool.pairFee).div(10000)) | ||
} | ||
|
||
return { | ||
timestamp, | ||
dailyFees: dailyFee.toString(), | ||
dailyRevenue: dailyFee.times(0.2).toString(), | ||
}; | ||
}; | ||
}; |