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
2 changed files
with
96 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,46 @@ | ||
import { request } from "graphql-request"; | ||
import { SimpleAdapter } from "../../adapters/types"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; | ||
|
||
const API_URL = 'http://localhost:3000/graphql'; | ||
|
||
interface IVolume { | ||
volume: string; | ||
timestamp: number; | ||
} | ||
|
||
const VolumeQuery = ` | ||
query GetAllPairStatisticsToday { | ||
pairs { | ||
getAllPairStatistics { | ||
volume | ||
timestamp | ||
} | ||
} | ||
} | ||
` | ||
|
||
const fetch = async (timestamp: number) => { | ||
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)) + 86400; | ||
const results: IVolume[] = (await request(API_URL, VolumeQuery)).pairs.getAllPairStatistics; | ||
let dailyVolume = results.filter((volumeInfo)=>{ | ||
return volumeInfo.timestamp === dayTimestamp; | ||
}) | ||
return { | ||
dailyVolume: dailyVolume ? `${dailyVolume[0].volume}` : undefined, | ||
timestamp: dayTimestamp, | ||
}; | ||
} | ||
|
||
const adapter: SimpleAdapter = { | ||
adapter: { | ||
[CHAIN.ELROND]: { | ||
fetch: fetch, | ||
runAtCurrTime: true, | ||
start: 1707782400 | ||
}, | ||
}, | ||
}; | ||
|
||
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,50 @@ | ||
import { Chain } from "@defillama/sdk/build/general"; | ||
import { Adapter, FetchResultFees } from "../../adapters/types"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
import { queryDune } from "../../helpers/dune"; | ||
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; | ||
import request from "graphql-request"; | ||
|
||
const API_URL = 'http://localhost:3000/graphql'; | ||
|
||
interface IFee { | ||
time: string; | ||
v2_fees: number; | ||
total_fees: number; | ||
} | ||
|
||
const fetch = (chain: Chain) => { | ||
return async (timestamp: number): Promise<FetchResultFees> => { | ||
const startTs = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)) | ||
const endTs = startTs + 86400; | ||
const feeQuery =`query Trading { | ||
trading { | ||
getDailyFee(from: ${startTs}, to: ${endTs}){ | ||
daily_fees | ||
daily_holders_revenue | ||
daily_protocol_revenue | ||
} | ||
} | ||
}`; | ||
|
||
const dailyFee = (await request(API_URL, feeQuery)); | ||
return { | ||
dailyFees: `${dailyFee.trading.getDailyFee.daily_fees}`, | ||
dailyHoldersRevenue: `${dailyFee.trading.getDailyFee.daily_holders_revenue}`, | ||
dailyProtocolRevenue: `${dailyFee.trading.getDailyFee.daily_protocol_revenue}`, | ||
timestamp, | ||
}; | ||
}; | ||
}; | ||
|
||
const adapter: Adapter = { | ||
adapter: { | ||
[CHAIN.ELROND]: { | ||
fetch: fetch(CHAIN.ARBITRUM), | ||
start: 1706745600, | ||
runAtCurrTime: true, | ||
} | ||
}, | ||
isExpensiveAdapter: true, | ||
}; | ||
export default adapter; |