Skip to content

Commit

Permalink
Merge branch 'master' into refactor-runAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmkeng authored Feb 5, 2024
2 parents b98f948 + 5ed5d92 commit 789dcd8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
23 changes: 16 additions & 7 deletions dexs/dackieswap-v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import customBackfill from "../../helpers/customBackfill";
import { DEFAULT_TOTAL_VOLUME_FACTORY, DEFAULT_TOTAL_VOLUME_FIELD, DEFAULT_DAILY_VOLUME_FACTORY, DEFAULT_DAILY_VOLUME_FIELD } from "../../helpers/getUniSubgraphVolume";
import { CHAIN } from "../../helpers/chains";
import type { ChainEndpoints, SimpleAdapter } from "../../adapters/types";
import type { Chain } from "@defillama/sdk/build/general";
import { getGraphDimensions } from "../../helpers/getUniSubgraph";
import {
DEFAULT_TOTAL_VOLUME_FACTORY,
DEFAULT_TOTAL_VOLUME_FIELD,
DEFAULT_DAILY_VOLUME_FACTORY,
DEFAULT_DAILY_VOLUME_FIELD
} from "../../helpers/getUniSubgraphVolume";
import {CHAIN} from "../../helpers/chains";
import type {ChainEndpoints, SimpleAdapter} from "../../adapters/types";
import type {Chain} from "@defillama/sdk/build/general";
import {getGraphDimensions} from "../../helpers/getUniSubgraph";

// Subgraphs endpoints
const endpoints: ChainEndpoints = {
[CHAIN.BASE]: "https://api.studio.thegraph.com/query/50473/subgraphs-exchange-v2/version/latest",
[CHAIN.OPTIMISM]: "https://api.studio.thegraph.com/query/50473/v2-optimism/version/latest",
};

// Fetch function to query the subgraphs
Expand Down Expand Up @@ -45,9 +51,12 @@ const adapter: SimpleAdapter = {
...acc,
[chain]: {
fetch: graphs(chain as Chain),
start: 1694217600,
start: async () =>
chain === CHAIN.BASE ? 1690173000
: chain === CHAIN.OPTIMISM ? 1705993200
: 0,
customBackfill: customBackfill(chain, graphs),
meta: { methodology },
meta: {methodology},
}
}
}, {})
Expand Down
7 changes: 7 additions & 0 deletions dexs/dackieswap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { getGraphDimensions } from "../../helpers/getUniSubgraph";
const v3Endpoint = {
[CHAIN.BASE]:
"https://api.studio.thegraph.com/query/50473/exchange-clmm/version/latest",
[CHAIN.OPTIMISM]:
"https://api.studio.thegraph.com/query/50473/v3-optimism/version/latest"
};

const VOLUME_USD = "volumeUSD";
Expand All @@ -30,6 +32,7 @@ const v3Graph = getGraphDimensions({

const v3StartTimes = {
[CHAIN.BASE]: 1691712000,
[CHAIN.OPTIMISM]: 1705993200,
} as IJSON<number>;

const adapter: SimpleAdapter = {
Expand All @@ -38,6 +41,10 @@ const adapter: SimpleAdapter = {
fetch: v3Graph(CHAIN.BASE),
start: async () => v3StartTimes[CHAIN.BASE]
},
[CHAIN.OPTIMISM]: {
fetch: v3Graph(CHAIN.OPTIMISM),
start: async () => v3StartTimes[CHAIN.OPTIMISM]
},
},
};

Expand Down
14 changes: 10 additions & 4 deletions dexs/levana/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import BigNumber from "bignumber.js";
import fetchURL from "../../utils/fetchURL";
import { MarketInfo} from "./types";
const plimit = require('p-limit');
const limit = plimit(1);

const INDEXER_URL = 'https://indexer-mainnet.levana.finance';

export async function fetchVolume(kind: "daily" | "total", marketInfos: MarketInfo[], timestampSeconds: number) {
const marketsStr = marketInfos.map(({addr}) => `market=${addr}`).join("&");
const timestamp = new Date(timestampSeconds * 1000).toISOString();
// it's either 1 day back or "all the days" back
const intervalDays = kind === "daily" ? 1 : Math.floor(timestampSeconds / (24 * 60 * 60));

const url = `${INDEXER_URL}/rolling_trade_volume?${marketsStr}&timestamp=${timestamp}&interval_days=${intervalDays}`
const url = (marketsStr: string) => `${INDEXER_URL}/rolling_trade_volume?market=${marketsStr}&timestamp=${timestamp}&interval_days=${intervalDays}`

const result = (await Promise.all(marketInfos.map(marketInfo => limit(() => fetchURL(url(marketInfo.addr))))))
.map((response: any) => response.data)
.map((data: any) => Number(data));

return result.reduce((a: number, b: number) => a + b, 0);
}

return new BigNumber((await fetchURL(url)));
}
18 changes: 11 additions & 7 deletions fees/banana-gun-trading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FetchResultFees, SimpleAdapter } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
import { getTimestampAtStartOfDayUTC } from "../utils/date";
import { getPrices } from "../utils/prices";
import { indexa, toBytea } from "../helpers/db"


interface IData {
Expand All @@ -15,27 +16,30 @@ const fetch = async (timestamp: number): Promise<FetchResultFees> => {
const now = new Date(timestamp * 1e3)
const dayAgo = new Date(now.getTime() - 1000 * 60 * 60 * 24)
try {
const transfer_txs = await sql`
const deployer:any[] = [
"0xf414d478934c29d9a80244a3626c681a71e53bb2", "0x37aab97476ba8dc785476611006fd5dda4eed66b"
].map(toBytea)

const query = indexa<any[]>`
SELECT
block_time,
encode(transaction_hash, 'hex') AS HASH,
encode(data, 'hex') AS data
encode(data, 'hex') AS data
FROM
ethereum.event_logs
ethereum.event_logs
WHERE
block_number > 17345415
AND contract_address IN (
SELECT DISTINCT address
FROM ethereum.traces
WHERE
block_number > 17345415
AND from_address IN ('\\xf414d478934c29d9a80244a3626c681a71e53bb2', '\\x37aab97476ba8dc785476611006fd5dda4eed66b')
AND from_address IN ${indexa(deployer)}
AND "type" = 'create'
and address is not null
)
AND topic_0 = '\\x72015ace03712f361249380657b3d40777dd8f8a686664cab48afd9dbbe4499f'
AND block_time BETWEEN ${dayAgo.toISOString()} AND ${now.toISOString()};
`;

const transfer_txs = await query.execute();
const transactions: IData[] = [...transfer_txs] as IData[]
const amount = transactions.map((e: IData) => {
const amount = Number('0x'+e.data.slice(0, 64)) / 10 ** 18
Expand Down

0 comments on commit 789dcd8

Please sign in to comment.