Skip to content

Commit

Permalink
add ash-perp
Browse files Browse the repository at this point in the history
  • Loading branch information
tuanh2000 committed Apr 3, 2024
1 parent 9b0e716 commit 845422e
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
46 changes: 46 additions & 0 deletions dexs/ash-perp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { request } from "graphql-request";
import { SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";

const API_URL = 'http://localhost:3000/graphql';

interface IVolume {
volume: string;
timestamp: number;
}

const VolumeQuery = `
query GetAllPairStatisticsToday {
pairs {
getAllPairStatistics {
volume
timestamp
}
}
}
`

const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)) + 86400;
const results: IVolume[] = (await request(API_URL, VolumeQuery)).pairs.getAllPairStatistics;
let dailyVolume = results.filter((volumeInfo)=>{
return volumeInfo.timestamp === dayTimestamp;
})
return {
dailyVolume: dailyVolume ? `${dailyVolume[0].volume}` : undefined,
timestamp: dayTimestamp,
};
}

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.ELROND]: {
fetch: fetch,
runAtCurrTime: true,
start: 1707782400
},
},
};

export default adapter;
50 changes: 50 additions & 0 deletions fees/ash-perp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Chain } from "@defillama/sdk/build/general";
import { Adapter, FetchResultFees } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { queryDune } from "../../helpers/dune";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";
import request from "graphql-request";

const API_URL = 'http://localhost:3000/graphql';

interface IFee {
time: string;
v2_fees: number;
total_fees: number;
}

const fetch = (chain: Chain) => {
return async (timestamp: number): Promise<FetchResultFees> => {
const startTs = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const endTs = startTs + 86400;
const feeQuery =`query Trading {
trading {
getDailyFee(from: ${startTs}, to: ${endTs}){
daily_fees
daily_holders_revenue
daily_protocol_revenue
}
}
}`;

const dailyFee = (await request(API_URL, feeQuery));
return {
dailyFees: `${dailyFee.trading.getDailyFee.daily_fees}`,
dailyHoldersRevenue: `${dailyFee.trading.getDailyFee.daily_holders_revenue}`,
dailyProtocolRevenue: `${dailyFee.trading.getDailyFee.daily_protocol_revenue}`,
timestamp,
};
};
};

const adapter: Adapter = {
adapter: {
[CHAIN.ELROND]: {
fetch: fetch(CHAIN.ARBITRUM),
start: 1706745600,
runAtCurrTime: true,
}
},
isExpensiveAdapter: true,
};
export default adapter;

0 comments on commit 845422e

Please sign in to comment.