Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drift #2211

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

drift #2211

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 25 additions & 28 deletions dexs/drift-protocol/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,28 @@ type DimentionResult = {
dailyRevenue?: number;
};

type IRequest = {
[key: string]: Promise<any>;
}
const requests: IRequest = {}

export async function fetchURLWithRetry(url: string, options: FetchOptions) {
const start = options.startOfDay;
const key = `${url}-${start}`;
if (!requests[key])
requests[key] = queryDune("4117889", {
start: start,
end: start + 24 * 60 * 60,
})
return requests[key]
}
let duneFetch;

async function getPerpDimensions(options: FetchOptions): Promise<DimentionResult> {
const volumeResponse = await fetchURLWithRetry("4117889", options)
const dailyVolume = volumeResponse[0].perpetual_volume;
const dailyFees = volumeResponse[0].total_taker_fee;
const dailyRevenue = volumeResponse[0].total_revenue;
return { dailyVolume, dailyFees, dailyRevenue };
async function getPerpDimensions(
options: FetchOptions,
): Promise<DimentionResult> {
if (!duneFetch) duneFetch = await queryDune("3782153");
const res = await duneFetch;
const [{ perpetual_volume, total_revenue, total_taker_fee }] = res;
return {
dailyVolume: perpetual_volume,
dailyFees: total_taker_fee,
dailyRevenue: total_revenue,
};
}

async function getSpotDimensions(options: FetchOptions): Promise<DimentionResult> {
const volumeResponse = await fetchURLWithRetry("4117889", options)
const dailyVolume = volumeResponse[0].spot_volume;
async function getSpotDimensions(
options: FetchOptions,
): Promise<DimentionResult> {
if (!duneFetch) duneFetch = await queryDune("3782153");
const res = await duneFetch;
const [{ perpetual_volume, total_volume }] = res;
const dailyVolume = total_volume - perpetual_volume;
return { dailyVolume };
}

Expand All @@ -63,14 +58,16 @@ const adapter: BreakdownAdapter = {
breakdown: {
swap: {
[CHAIN.SOLANA]: {
fetch: (_t: any, _tt: any, options: FetchOptions) => fetch("spot", options),
start: '2023-07-25',
fetch: (_t: any, _tt: any, options: FetchOptions) =>
fetch("spot", options),
start: "2023-07-25",
},
},
derivatives: {
[CHAIN.SOLANA]: {
fetch: (_t: any, _tt: any, options: FetchOptions) => fetch("perp", options),
start: '2023-07-25',
fetch: (_t: any, _tt: any, options: FetchOptions) =>
fetch("perp", options),
start: "2023-07-25",
},
},
},
Expand Down
Loading