Skip to content

Commit 6a1e490

Browse files
committed
track kura fees & volume
1 parent 72c71eb commit 6a1e490

3 files changed

Lines changed: 95 additions & 23 deletions

File tree

dexs/kura-v2.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* import { uniV2Exports } from "../helpers/uniswap";
2+
3+
export default uniV2Exports({
4+
sei: {
5+
factory: '0xAEbdA18889D6412E237e465cA25F5F346672A2eC',
6+
}
7+
}) */
8+
9+
import { univ2Adapter2 } from "../helpers/getUniSubgraphVolume";
10+
import { CHAIN } from "../helpers/chains";
11+
import { SimpleAdapter } from "../adapters/types";
12+
13+
const fetch = univ2Adapter2({
14+
endpoints: {
15+
[CHAIN.SEI]: "https://api.goldsky.com/api/public/project_cm9ghm7cnxuaa01x5g6pfchp7/subgraphs/sei/2/gn"
16+
},
17+
factoriesName: 'legacyFactories',
18+
totalFeesField: 'totalFeeUSD'
19+
})
20+
21+
const adapter: SimpleAdapter = {
22+
version: 2,
23+
fetch,
24+
chains: [CHAIN.SEI],
25+
}
26+
27+
export default adapter

dexs/kura-v3.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// import { uniV3Exports } from "../helpers/uniswap";
2+
3+
// export default uniV3Exports({
4+
// sei: {
5+
// factory: '0xd0c54c480fD00DDa4DF1BbE041A6881f2F09111e',
6+
// }
7+
// })
8+
9+
10+
import { univ2Adapter2 } from "../helpers/getUniSubgraphVolume";
11+
import { CHAIN } from "../helpers/chains";
12+
import { SimpleAdapter } from "../adapters/types";
13+
14+
const fetch = univ2Adapter2({
15+
endpoints: {
16+
[CHAIN.SEI]: "https://api.goldsky.com/api/public/project_cm9ghm7cnxuaa01x5g6pfchp7/subgraphs/sei/2/gn"
17+
},
18+
factoriesName: 'clFactories',
19+
totalFeesField: 'totalFeesUSD'
20+
})
21+
22+
const adapter: SimpleAdapter = {
23+
version: 2,
24+
fetch,
25+
chains: [CHAIN.SEI],
26+
}
27+
28+
export default adapter

helpers/getUniSubgraphVolume.ts

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ interface IGetChainVolumeParams {
4141
totalVolume: {
4242
factory: string,
4343
field: string,
44-
filterParams?: IGetChainVolumeFilterParams[],
44+
filterParams?: IGetChainVolumeFilterParams[],
4545
},
4646
dailyVolume?: {
4747
factory: string,
4848
field: string,
4949
dateField?: string,
5050
},
51+
totalFeesField?: string,
5152
customDailyVolume?: string,
5253
hasDailyVolume?: boolean
5354
hasTotalVolume?: boolean
@@ -117,7 +118,7 @@ function getChainVolume({
117118
switch (item.name) {
118119
case "id":
119120
graphQueryTodayTotalVolumeVariables["id"] = id;
120-
graphQueryYesterdayTotalVolumeVariables["id"] = id-1
121+
graphQueryYesterdayTotalVolumeVariables["id"] = id - 1
121122
default:
122123
}
123124
});
@@ -131,7 +132,7 @@ function getChainVolume({
131132
if (hasDailyVolume && !dailyVolumeValue) {
132133
graphResDaily = await request(graphUrls[chain], alternativeDaily(getUniqStartOfTodayTimestamp(new Date(endTimestamp * 1000))));
133134
const factory = dailyVolume.factory.toLowerCase().charAt(dailyVolume.factory.length - 1) === 's' ? dailyVolume.factory : `${dailyVolume.factory}s`
134-
dailyVolumeValue = graphResDaily ? graphResDaily[`${factory }`].reduce((p: any, c: any) => p + Number(c[`${dailyVolume.field}`]), 0) : undefined;
135+
dailyVolumeValue = graphResDaily ? graphResDaily[`${factory}`].reduce((p: any, c: any) => p + Number(c[`${dailyVolume.field}`]), 0) : undefined;
135136
}
136137
if (!hasDailyVolume) {
137138
const fromBlock = await getFromBlock()
@@ -160,6 +161,7 @@ function getChainVolume2({
160161
factory: DEFAULT_TOTAL_VOLUME_FACTORY,
161162
field: DEFAULT_TOTAL_VOLUME_FIELD,
162163
},
164+
totalFeesField,
163165
hasTotalVolume = true,
164166
getCustomBlock = undefined,
165167
}: IGetChainVolumeParams) {
@@ -168,6 +170,7 @@ function getChainVolume2({
168170
block: { number: $block }
169171
) {
170172
${totalVolume.field}
173+
${totalFeesField ? totalFeesField : ''}
171174
}
172175
`;
173176

@@ -178,19 +181,24 @@ function getChainVolume2({
178181
const { endTimestamp, startTimestamp, getEndBlock, getStartBlock } = options;
179182

180183
const endBlock = (await (getCustomBlock ? getCustomBlock(endTimestamp) : getEndBlock())) ?? undefined;
181-
const startBlock = (await (getCustomBlock ? getCustomBlock(startTimestamp) :getStartBlock())) ?? undefined;
184+
const startBlock = (await (getCustomBlock ? getCustomBlock(startTimestamp) : getStartBlock())) ?? undefined;
182185

183-
const graphResTotal = hasTotalVolume ? await request(graphUrls[chain], graphQueryTotalVolume, { block: endBlock }): undefined;
186+
const graphResTotal = hasTotalVolume ? await request(graphUrls[chain], graphQueryTotalVolume, { block: endBlock }) : undefined;
184187
const total = graphResTotal ? graphResTotal[totalVolume.factory]?.reduce((total: number, factory: any) => total + Number(factory[totalVolume.field]), 0) : undefined;
188+
const totalFees = totalFeesField && graphResTotal ? graphResTotal[totalVolume.factory]?.reduce((total: number, factory: any) => total + Number(factory[totalFeesField]), 0) : undefined;
185189

186190
const graphResPrevTotal = hasTotalVolume ? await request(graphUrls[chain], graphQueryTotalVolume, { block: startBlock }) : undefined;
187191
const prevTotal = graphResPrevTotal ? graphResPrevTotal[totalVolume.factory]?.reduce((total: number, factory: any) => total + Number(factory[totalVolume.field]), 0) : undefined;
192+
const prevTotalFees = totalFeesField && graphResPrevTotal ? graphResPrevTotal[totalVolume.factory]?.reduce((total: number, factory: any) => total + Number(factory[totalFeesField]), 0) : undefined;
188193

189194
let dailyVolumeValue = total - prevTotal
190195

191-
return {
196+
const response: any = {
192197
dailyVolume: dailyVolumeValue,
193-
};
198+
}
199+
if (totalFeesField)
200+
response.dailyFees = totalFees - prevTotalFees
201+
return response
194202
};
195203
};
196204
}
@@ -211,8 +219,8 @@ function getChainVolumeWithGasToken({
211219
hasTotalVolume = true,
212220
getCustomBlock = undefined,
213221
priceToken,
214-
}: IGetChainVolumeParams & {priceToken:string}) {
215-
const basic = getChainVolume({graphUrls, totalVolume, dailyVolume, customDailyVolume, hasDailyVolume, hasTotalVolume, getCustomBlock})
222+
}: IGetChainVolumeParams & { priceToken: string }) {
223+
const basic = getChainVolume({ graphUrls, totalVolume, dailyVolume, customDailyVolume, hasDailyVolume, hasTotalVolume, getCustomBlock })
216224
return (chain: Chain) => {
217225
return async (_a: any, _b: any, options: FetchOptions) => {
218226
const {
@@ -236,39 +244,46 @@ function getChainVolumeWithGasToken2({
236244
factory: DEFAULT_TOTAL_VOLUME_FACTORY,
237245
field: 'totalVolumeETH',
238246
},
247+
totalFeesField,
239248
getCustomBlock = undefined,
240249
priceToken,
241-
}: IGetChainVolumeParams & {priceToken:string}) {
242-
const basic = getChainVolume2({graphUrls, totalVolume, getCustomBlock})
250+
}: IGetChainVolumeParams & { priceToken: string }) {
251+
const basic = getChainVolume2({ graphUrls, totalVolume, totalFeesField, getCustomBlock })
243252
return (chain: Chain) => {
244253
return async (options: FetchOptions): Promise<FetchResultV2> => {
245254
const {
246255
dailyVolume,
256+
dailyFees,
247257
} = await basic(chain)(options);
248258

249-
const timestamp = options.endTimestamp
250-
const balances = new Balances({ chain, timestamp })
259+
const balances = options.createBalances()
251260
balances.add(priceToken, Number(dailyVolume).toFixed(0), { skipChain: true })
261+
let dailyFeesObj = options.createBalances()
262+
if (totalFeesField)
263+
dailyFeesObj.add(priceToken, Number(dailyFees).toFixed(0), { skipChain: true })
252264

253-
return {
254-
dailyVolume: await balances.getUSDString(),
265+
const response: any = {
266+
dailyVolume: balances,
255267
}
268+
if (totalFeesField)
269+
response.dailyFees = dailyFeesObj
270+
return response
256271
};
257272
};
258273
}
259274

260275
function univ2Adapter({
261-
endpoints = {} as {[chain: string]: string},
276+
endpoints = {} as { [chain: string]: string },
262277
factoriesName = DEFAULT_TOTAL_VOLUME_FACTORY,
263278
dayData = DEFAULT_DAILY_VOLUME_FACTORY,
264279
totalVolume = DEFAULT_TOTAL_VOLUME_FIELD,
265280
totalVolumeFilterParams = undefined as IGetChainVolumeFilterParams[] | undefined,
266281
dailyVolume = DEFAULT_DAILY_VOLUME_FIELD,
267282
dailyVolumeTimestampField = DEFAULT_DATE_FIELD,
268283
hasTotalVolume = true,
269-
hasDailyVolume = undefined as boolean|undefined,
270-
gasToken = null as string|null
271-
}){
284+
hasDailyVolume = undefined as boolean | undefined,
285+
gasToken = null as string | null
286+
}) {
272287
const graphs = (gasToken === null ? getChainVolume : getChainVolumeWithGasToken as typeof getChainVolume)({
273288
graphUrls: endpoints,
274289
hasTotalVolume,
@@ -285,23 +300,25 @@ function univ2Adapter({
285300
hasDailyVolume,
286301
priceToken: gasToken
287302
} as any);
288-
return async (_a:any, _b:any, options: FetchOptions) => {
303+
return async (_a: any, _b: any, options: FetchOptions) => {
289304
return graphs(options.chain)(_a, _b, options)
290305
}
291306
}
292307

293308
function univ2Adapter2({
294-
endpoints = {} as {[chain: string]: string},
309+
endpoints = {} as { [chain: string]: string },
295310
factoriesName = DEFAULT_TOTAL_VOLUME_FACTORY,
296311
totalVolume = DEFAULT_TOTAL_VOLUME_FIELD,
297-
gasToken = null as string|null,
298-
}){
312+
totalFeesField = null as string | null,
313+
gasToken = null as string | null,
314+
}) {
299315
const graphs = (gasToken === null ? getChainVolume2 : getChainVolumeWithGasToken2 as typeof getChainVolume2)({
300316
graphUrls: endpoints,
301317
totalVolume: {
302318
factory: factoriesName,
303319
field: totalVolume
304320
},
321+
totalFeesField,
305322
priceToken: gasToken
306323
} as any);
307324
return async (options: FetchOptions) => {

0 commit comments

Comments
 (0)