Skip to content

Commit

Permalink
fix clober dex
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Jan 10, 2025
1 parent 6c8d2c7 commit 8ff559b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 90 deletions.
26 changes: 0 additions & 26 deletions dexs/clober-v2/const.ts

This file was deleted.

85 changes: 25 additions & 60 deletions dexs/clober-v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,40 @@
import type {SimpleAdapter} from "../../adapters/types";
import {FetchOptions, FetchResultV2, FetchV2} from "../../adapters/types";
import {getTimestampAtStartOfDayUTC} from "../../utils/date"
import {CHAIN} from "../../helpers/chains";
import {CONTRACT_INFOS} from "./const";

const fetch: FetchV2 = async (options: FetchOptions): Promise<FetchResultV2> => {
const dayTimestamp = getTimestampAtStartOfDayUTC(options.toTimestamp)

const dailyVolume = options.createBalances()

const bookInfos: any = {}
const CONTRACT_INFO = CONTRACT_INFOS[options.chain];

const openEvents = await options.getLogs({
target: CONTRACT_INFO.bookManagerContract.address,
fromBlock: CONTRACT_INFO.bookManagerContract.fromBlock,
eventAbi: CONTRACT_INFO.bookManagerContract.abi.openEvent,
onlyArgs: true,
})
for (const open of openEvents) {
const bookId = open.id;
bookInfos[bookId] = {
quote: open.quote,
unitSize: open.unitSize,
}
}

const dailyTakeEvents = await options.getLogs({
target: CONTRACT_INFO.bookManagerContract.address,
eventAbi: CONTRACT_INFO.bookManagerContract.abi.takeEvent,
onlyArgs: true,
})
const takeEvents = [
{
events: dailyTakeEvents,
volume: dailyVolume,
},
]
for (const {events, volume} of takeEvents) {
for (const take of events) {
const bookId = take.bookId;
const bookInfo = bookInfos[bookId];
if (!bookInfo) {
continue;
}
const quote = bookInfo.quote;
const quoteVolume = take.unit * bookInfo.unitSize;
volume.add(quote, quoteVolume);
}
}

return {
dailyVolume: dailyVolume,
timestamp: dayTimestamp,
};
import type { SimpleAdapter } from "../../adapters/types";
import { FetchOptions, FetchResultV2, FetchV2 } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
const abi = {
getBookKey: "function getBookKey(uint192 id) view returns ((address base, uint64 unitSize, address quote, uint24 makerPolicy, address hooks, uint24 takerPolicy))",
take: 'event Take(uint192 indexed bookId, address indexed user, int24 tick, uint64 unit)'
}
const bookManagerContract = {
[CHAIN.BASE]: '0x382CCccbD3b142D7DA063bF68cd0c89634767F76',
[CHAIN.ERA]: '0xAaA0e933e1EcC812fc075A81c116Aa0a82A5bbb8',
}

const fetch: FetchV2 = async ({ getLogs, createBalances, chain, api }: FetchOptions): Promise<FetchResultV2> => {
const dailyVolume = createBalances()

const target = bookManagerContract[chain]
const takeEvents = await getLogs({ target, eventAbi: abi.take, })

const bookKeys = takeEvents.map(i => i.bookId.toString())
const tokens = await api.multiCall({ abi: abi.getBookKey, calls: bookKeys, target })
takeEvents.forEach((i, idx) => dailyVolume.add(tokens[idx].quote, i.unit))

return { dailyVolume, };
};

const adapter: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.BASE]: {
fetch: fetch,
// runAtCurrTime: true,
fetch,
start: '2024-06-12',
meta: {
methodology: 'Volume is calculated by summing the quote token volume of all trades on the protocol.',
}
},
[CHAIN.ERA]: {
fetch: fetch,
// runAtCurrTime: true,
fetch,
start: '2024-06-12',
meta: {
methodology: 'Volume is calculated by summing the quote token volume of all trades on the protocol.',
Expand Down
7 changes: 3 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8ff559b

Please sign in to comment.