-
Notifications
You must be signed in to change notification settings - Fork 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 #653 from joehquak/add/sobal
Add: Sobal DEX Volume & Fees
- Loading branch information
Showing
3 changed files
with
134 additions
and
3 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,49 @@ | ||
import { ChainEndpoints, BreakdownAdapter, BaseAdapter } from "../../adapters/types"; | ||
import { getChainVolume } from "../../helpers/getUniSubgraphVolume"; | ||
import customBackfill from "../../helpers/customBackfill"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
import { Chain } from "@defillama/sdk/build/general"; | ||
import { getStartTimestamp } from "../../helpers/getStartTimestamp"; | ||
|
||
const endpoints: ChainEndpoints = { | ||
[CHAIN.NEON]: | ||
"https://neon-subgraph.sobal.fi/sobal-pools", | ||
}; | ||
|
||
const graphParams = { | ||
totalVolume: { | ||
factory: "balancers", | ||
field: "totalSwapVolume", | ||
}, | ||
hasDailyVolume: false, | ||
} | ||
|
||
const graphs = getChainVolume({ | ||
graphUrls: endpoints, | ||
...graphParams | ||
}); | ||
|
||
const adapter: BreakdownAdapter = { | ||
breakdown: { | ||
v2: Object.keys(endpoints).reduce((acc, chain) => { | ||
return { | ||
...acc, | ||
[chain]: { | ||
fetch: graphs(chain as Chain), | ||
customBackfill: customBackfill(chain as Chain, graphs), | ||
start: getStartTimestamp({ | ||
endpoints, | ||
chain: chain, | ||
dailyDataField: `balancerSnapshots`, | ||
dateField: 'timestamp', | ||
volumeField: 'totalSwapVolume' | ||
}), | ||
} | ||
} | ||
}, {} as BaseAdapter) | ||
} | ||
} | ||
|
||
export default adapter; | ||
|
||
// TODO custom backfill have to get specific block at start of each day |
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,81 @@ | ||
import { Adapter } from "../adapters/types"; | ||
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 BigNumber from "bignumber.js"; | ||
import { getTimestampAtStartOfDayUTC } from "../utils/date"; | ||
|
||
const v2Endpoints = { | ||
[CHAIN.NEON]: | ||
"https://neon-subgraph.sobal.fi/sobal-pools", | ||
}; | ||
|
||
const v2Graphs = (graphUrls: ChainEndpoints) => { | ||
return (chain: Chain) => { | ||
return async (timestamp: number) => { | ||
const startTimestamp = getTimestampAtStartOfDayUTC(timestamp) | ||
const dayId = Math.floor(startTimestamp / 86400) | ||
|
||
const graphQuery = gql | ||
`query fees($dayId: String!, $yesterdayId: String!) { | ||
today: balancerSnapshot(id: $dayId) { | ||
totalSwapFee | ||
} | ||
yesterday: balancerSnapshot(id: $yesterdayId) { | ||
totalSwapFee | ||
} | ||
}`; | ||
|
||
const graphRes = await request(graphUrls[chain], graphQuery, { | ||
dayId: `2-${dayId}`, | ||
yesterdayId: `2-${dayId - 1}` | ||
}); | ||
const currentTotalSwapFees = new BigNumber(graphRes["today"]["totalSwapFee"]) | ||
|
||
const dailyFee = currentTotalSwapFees.minus(new BigNumber(graphRes["yesterday"]["totalSwapFee"])) | ||
|
||
// Currently 50% of Fees | ||
const dailyRevenue = dailyFee.multipliedBy(0.5); | ||
const totalRevenue = currentTotalSwapFees.multipliedBy(0.5); | ||
|
||
return { | ||
timestamp, | ||
totalUserFees: graphRes["today"]["totalSwapFee"], | ||
dailyUserFees: dailyFee.toString(), | ||
totalFees: graphRes["today"]["totalSwapFee"], | ||
dailyFees: dailyFee.toString(), | ||
totalRevenue: totalRevenue.toString(), | ||
dailyRevenue: dailyRevenue.toString(), | ||
totalProtocolRevenue: totalRevenue.toString(), | ||
dailyProtocolRevenue: dailyRevenue.toString(), | ||
totalSupplySideRevenue: new BigNumber(graphRes["today"]["totalSwapFee"]).minus(totalRevenue.toString()).toString(), | ||
dailySupplySideRevenue: new BigNumber(dailyFee.toString()).minus(dailyRevenue.toString()).toString(), | ||
}; | ||
}; | ||
}; | ||
}; | ||
|
||
const methodology = { | ||
UserFees: "Trading fees paid by users, ranging from 0.0001% to 10%", | ||
Fees: "All trading fees collected (doesn't include withdrawal and flash loan fees)", | ||
Revenue: "Protocol revenue from all fees collected", | ||
ProtocolRevenue: "Currently no protocol swap fee in place", | ||
SupplySideRevenue: "A small percentage of the trade paid by traders to pool LPs, set by the pool creator or managed by protocol.", | ||
} | ||
|
||
const adapter: Adapter = { | ||
breakdown: { | ||
v2: { | ||
[CHAIN.NEON]: { | ||
fetch: v2Graphs(v2Endpoints)(CHAIN.NEON), | ||
start: async () => 1689613200, // 17TH JULY 5PM GMT | ||
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