-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #876 from MoonKnightDev/master
Add based-markets
- Loading branch information
Showing
2 changed files
with
204 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,91 @@ | ||
import request, { gql } from "graphql-request"; | ||
import { FetchResultVolume, SimpleAdapter } from "../../adapters/types"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
import BigNumber from "bignumber.js"; | ||
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; | ||
|
||
const ONE_DAY_IN_SECONDS = 60 * 60 * 24 | ||
|
||
const endpoint = "https://api.thegraph.com/subgraphs/name/symmiograph/base_analytics_8" | ||
|
||
const query = gql` | ||
query stats($from: String!, $to: String!) { | ||
dailyHistories(where: {timestamp_gte: $from, timestamp_lte: $to, accountSource: "0x5dE6949717F3AA8E0Fbed5Ce8B611Ebcf1e44AE9"}){ | ||
timestamp | ||
platformFee | ||
accountSource | ||
tradeVolume | ||
} | ||
totalHistories(where: {accountSource: "0x5dE6949717F3AA8E0Fbed5Ce8B611Ebcf1e44AE9"}) { | ||
timestamp | ||
platformFee | ||
accountSource | ||
tradeVolume | ||
} | ||
} | ||
` | ||
|
||
|
||
interface IGraphResponse { | ||
dailyHistories: Array<{ | ||
tiemstamp: string, | ||
platformFee: string, | ||
accountSource: string, | ||
tradeVolume: string | ||
}> | ||
totalHistories: Array<{ | ||
tiemstamp: string, | ||
platformFee: string, | ||
accountSource: string, | ||
tradeVolume: BigNumber | ||
}> | ||
} | ||
|
||
const toString = (x: BigNumber) => { | ||
if (x.isEqualTo(0)) return undefined | ||
return x.toString() | ||
} | ||
|
||
const fetchVolume = async (timestamp: number): Promise<FetchResultVolume> => { | ||
const response: IGraphResponse = await request(endpoint, query, { | ||
from: String(timestamp - ONE_DAY_IN_SECONDS), | ||
to: String(timestamp) | ||
}) | ||
|
||
|
||
let dailyVolume = new BigNumber(0); | ||
response.dailyHistories.forEach(data => { | ||
dailyVolume = dailyVolume.plus(new BigNumber(data.tradeVolume)) | ||
}); | ||
|
||
let totalVolume = new BigNumber(0); | ||
response.totalHistories.forEach(data => { | ||
totalVolume = totalVolume.plus(new BigNumber(data.tradeVolume)) | ||
}); | ||
|
||
dailyVolume = dailyVolume.dividedBy(new BigNumber(1e18)) | ||
totalVolume = totalVolume.dividedBy(new BigNumber(1e18)) | ||
|
||
const _dailyVolume = toString(dailyVolume) | ||
const _totalVolume = toString(totalVolume) | ||
|
||
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date((timestamp * 1000))) | ||
|
||
return { | ||
timestamp: dayTimestamp, | ||
dailyVolume: _dailyVolume, | ||
totalVolume: _totalVolume, | ||
} | ||
|
||
} | ||
|
||
const adapter: SimpleAdapter = { | ||
adapter: { | ||
[CHAIN.BASE]: { | ||
fetch: fetchVolume, | ||
start: async () => 1691332847 | ||
} | ||
} | ||
} | ||
|
||
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,113 @@ | ||
import request, { gql } from "graphql-request"; | ||
import { CHAIN } from "../helpers/chains"; | ||
import BigNumber from "bignumber.js"; | ||
import { getUniqStartOfTodayTimestamp } from "../helpers/getUniSubgraphVolume"; | ||
import { FetchResultFees, SimpleAdapter } from "../adapters/types"; | ||
|
||
const ONE_DAY_IN_SECONDS = 60 * 60 * 24 | ||
|
||
const endpoint = "https://api.thegraph.com/subgraphs/name/symmiograph/base_analytics_8" | ||
|
||
const query = gql` | ||
query stats($from: String!, $to: String!) { | ||
dailyHistories(where: {timestamp_gte: $from, timestamp_lte: $to, accountSource: "0x5dE6949717F3AA8E0Fbed5Ce8B611Ebcf1e44AE9"}){ | ||
timestamp | ||
platformFee | ||
accountSource | ||
tradeVolume | ||
} | ||
totalHistories(where: {accountSource: "0x5dE6949717F3AA8E0Fbed5Ce8B611Ebcf1e44AE9"}) { | ||
timestamp | ||
platformFee | ||
accountSource | ||
tradeVolume | ||
} | ||
} | ||
` | ||
|
||
|
||
interface IGraphResponse { | ||
dailyHistories: Array<{ | ||
tiemstamp: string, | ||
platformFee: string, | ||
accountSource: string, | ||
tradeVolume: string | ||
}> | ||
totalHistories: Array<{ | ||
tiemstamp: string, | ||
platformFee: string, | ||
accountSource: string, | ||
tradeVolume: BigNumber | ||
}> | ||
} | ||
|
||
const toString = (x: BigNumber) => { | ||
if (x.isEqualTo(0)) return undefined | ||
return x.toString() | ||
} | ||
|
||
const fetchVolume = async (timestamp: number): Promise<FetchResultFees> => { | ||
const response: IGraphResponse = await request(endpoint, query, { | ||
from: String(timestamp - ONE_DAY_IN_SECONDS), | ||
to: String(timestamp) | ||
}) | ||
|
||
|
||
let dailyFees = new BigNumber(0); | ||
response.dailyHistories.forEach(data => { | ||
dailyFees = dailyFees.plus(new BigNumber(data.platformFee)) | ||
}); | ||
|
||
let totalFees = new BigNumber(0); | ||
response.totalHistories.forEach(data => { | ||
totalFees = totalFees.plus(new BigNumber(data.platformFee)) | ||
}); | ||
|
||
dailyFees = dailyFees.dividedBy(new BigNumber(1e18)) | ||
totalFees = totalFees.dividedBy(new BigNumber(1e18)) | ||
|
||
const _dailyFees = toString(dailyFees) | ||
const _totalFees = toString(totalFees) | ||
|
||
const dailyUserFees = _dailyFees; | ||
const dailyRevenue = _dailyFees; | ||
const dailyProtocolRevenue = '0'; | ||
const dailyHoldersRevenue = _dailyFees; | ||
const dailySupplySideRevenue = '0'; | ||
|
||
const totalUserFees = _totalFees; | ||
const totalRevenue = _totalFees; | ||
const totalProtocolRevenue = '0'; | ||
const totalSupplySideRevenue = '0'; | ||
|
||
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date((timestamp * 1000))) | ||
|
||
return { | ||
timestamp: dayTimestamp, | ||
|
||
dailyFees: _dailyFees, | ||
totalFees: _totalFees, | ||
|
||
dailyUserFees, | ||
dailyRevenue, | ||
dailyProtocolRevenue, | ||
dailyHoldersRevenue, | ||
dailySupplySideRevenue, | ||
totalUserFees, | ||
totalRevenue, | ||
totalProtocolRevenue, | ||
totalSupplySideRevenue, | ||
} | ||
|
||
} | ||
|
||
|
||
const adapter: SimpleAdapter = { | ||
adapter: { | ||
[CHAIN.BASE]: { | ||
fetch: fetchVolume, | ||
start: async () => 1691332847 | ||
} | ||
} | ||
} | ||
export default adapter; |