-
Notifications
You must be signed in to change notification settings - Fork 952
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
1 parent
35b2682
commit e515b30
Showing
1 changed file
with
15 additions
and
29 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,60 +1,46 @@ | ||
import { CHAIN } from "../../helpers/chains"; | ||
import { request, gql } from "graphql-request"; | ||
import type { ChainEndpoints } from "../../adapters/types" | ||
import { Chain } from '@defillama/sdk/build/general'; | ||
import type { ChainEndpoints } from "../../adapters/types"; | ||
import { Chain } from "@defillama/sdk/build/general"; | ||
import BigNumber from "bignumber.js"; | ||
import { Adapter } from "../../adapters/types" | ||
import { Adapter } from "../../adapters/types"; | ||
|
||
const endpoints = { | ||
[CHAIN.ARBITRUM]: "https://subgraph.satsuma-prod.com/e66b06ce96d2/bufferfinance/v2.5-arbitrum-mainnet/api" | ||
} | ||
[CHAIN.ARBITRUM]: "https://satsuma-dump.buffer.finance/", | ||
}; | ||
|
||
export function _getDayId(timestamp: number): string { | ||
let dayTimestamp = Math.floor((timestamp - 16 * 3600) / 86400); | ||
return dayTimestamp.toString(); | ||
} | ||
|
||
const graphs = (graphUrls: ChainEndpoints) => { | ||
const graphs = (baseUrls: ChainEndpoints) => { | ||
return (chain: Chain) => { | ||
return async (timestamp: number) => { | ||
const dateId = _getDayId(timestamp); | ||
|
||
const graphQuery = gql | ||
`{ | ||
defillamaFeeStat(id: ${dateId}) { | ||
fee | ||
} | ||
}`; | ||
|
||
const graphRes = await request(graphUrls[chain], graphQuery); | ||
|
||
const dailyFee = new BigNumber(graphRes.defillamaFeeStat.fee).div(1000000); | ||
// const protocolRev = new BigNumber(graphRes.dailyRevenueAndFee.settlementFee).div(1000000).times(0.05); | ||
// const userHolderRev = new BigNumber(graphRes.dailyRevenueAndFee.settlementFee).div(1000000).times(0.4); | ||
// const supplySideRev = new BigNumber(graphRes.dailyRevenueAndFee.settlementFee).div(1000000).times(0.55); | ||
const dailyRev = new BigNumber(graphRes.defillamaFeeStat.fee).div(1000000); | ||
const url = new URL(baseUrls[chain]); | ||
url.searchParams.append("day", dateId); | ||
|
||
const response = await fetch(url); | ||
const dailyFee = (await response.json()).fee / 1000000; | ||
return { | ||
timestamp, | ||
dailyFees: dailyFee.toString(), | ||
// dailyProtocolRevenue: protocolRev.toString(), | ||
// dailyUserHolderRevenue: userHolderRev.toString(), | ||
// dailySupplySideRevenue: supplySideRev.toString(), | ||
dailyRevenue: dailyRev.toString() | ||
dailyRevenue: dailyFee.toString(), | ||
}; | ||
}; | ||
}; | ||
}; | ||
|
||
|
||
const adapter: Adapter = { | ||
adapter: { | ||
[CHAIN.ARBITRUM]: { | ||
fetch: graphs(endpoints)(CHAIN.ARBITRUM), | ||
start: 1674950400 , | ||
fetch: graphs(endpoints)(CHAIN.ARBITRUM), | ||
start: 1674950400, | ||
}, | ||
}, | ||
version: 1 | ||
} | ||
version: 1, | ||
}; | ||
|
||
export default adapter; |