Skip to content

Commit

Permalink
Merge pull request #1 from DefiLlama/master
Browse files Browse the repository at this point in the history
pull
  • Loading branch information
Anirudha619 committed Jul 26, 2024
2 parents eebd650 + b148170 commit 14dc8dd
Show file tree
Hide file tree
Showing 63 changed files with 2,324 additions and 415 deletions.
21 changes: 12 additions & 9 deletions aggregator-derivatives/bitoro/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fetchURL from "../../utils/fetchURL";
import { FetchResultV2 } from "../../adapters/types";
import { FetchResult, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";

const BitoroX_BASE_URL = "https://min-api.bitoro.network/btr/stats/global";
Expand All @@ -15,29 +15,31 @@ const getBitoroProUrl = (startTime: number, endTime: number): string => {
return `${BitoroPro_BASE_URL}?start=${startTime}&end=${endTime}`;
}

const fetchBitoroX = async (options: any): Promise<FetchResultV2> => {
const { fromTimestamp, toTimestamp } = options;
const dailyVolume = await fetchURL(getBitoroXUrl(fromTimestamp, toTimestamp));
const totalVolume = await fetchURL(getBitoroXUrl(startTimestamp_bitoro_x, toTimestamp));
const fetchBitoroX = async (_:any, _b:any ,options: any): Promise<FetchResult> => {
const { endTimestamp, startTimestamp } = options;
const dailyVolume = await fetchURL(getBitoroXUrl(startTimestamp, endTimestamp));
const totalVolume = await fetchURL(getBitoroXUrl(startTimestamp_bitoro_x, endTimestamp));

return {
timestamp: startTimestamp,
dailyVolume: dailyVolume.volume || 0,
totalVolume: totalVolume.volume || 0,
};
};

const fetchBitoroPro = async (options: any): Promise<FetchResultV2> => {
const fetchBitoroPro = async (_:any, _b:any ,options: any): Promise<FetchResult> => {
const { fromTimestamp, toTimestamp } = options;
const dailyVolume = await fetchURL(getBitoroProUrl(fromTimestamp, toTimestamp));
const totalVolume = await fetchURL(getBitoroProUrl(startTimestamp_bitoro_pro, toTimestamp));

return {
timestamp: fromTimestamp,
dailyVolume: dailyVolume.volume || 0,
totalVolume: totalVolume.volume || 0,
};
};

export default {
const adapter: SimpleAdapter = {
adapter: {
[CHAIN.ARBITRUM]: {
fetch: fetchBitoroX,
Expand All @@ -47,6 +49,7 @@ export default {
fetch: fetchBitoroPro,
start: startTimestamp_bitoro_pro
}
},
version: 2
}
}

export default adapter;
8 changes: 4 additions & 4 deletions aggregator-derivatives/perpie/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
BreakdownAdapter,
Fetch,
FetchOptions,
FetchResult,
FetchResultV2,
Expand Down Expand Up @@ -45,14 +46,13 @@ const fetchVolumeAndFees: (chain: string) => FetchV2 =
};
};

const fetchAll: (chain: string) => FetchV2 =
const fetchAll: (chain: string) => Fetch =
(chain: string) =>
async (options: FetchOptions): Promise<FetchResultV2> => {
async (_a: any, _t: any ,options: FetchOptions): Promise<FetchResult> => {
const volumeAndFees = await fetchVolumeAndFees(chain)(options);
return { ...volumeAndFees } as FetchResultV2;
return { ...volumeAndFees } as FetchResult;
};
const adapter: BreakdownAdapter = {
version: 2,
isExpensiveAdapter: true,
breakdown: {
derivatives: {
Expand Down
8 changes: 4 additions & 4 deletions aggregator-derivatives/vooi/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fetchURL from "../../utils/fetchURL";
import { FetchResult, FetchResultV2, SimpleAdapter } from "../../adapters/types";
import { FetchResult } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";

const URL = "https://defilama-stats.vooi.workers.dev/";
Expand All @@ -11,12 +11,12 @@ interface IAPIResponse {
dailyVolume: string;
totalVolume: string;
}
const fetch = async (options: any): Promise<FetchResultV2> => {
let timestamp = options.toTimestamp
const fetch = async (timestamp: number): Promise<FetchResult> => {
const { dailyVolume, totalVolume }: IAPIResponse = (
(await fetchURL(`${URL}${endpoint}?ts=${timestamp}`)).data
);
return {
timestamp,
dailyVolume,
totalVolume,
};
Expand All @@ -29,5 +29,5 @@ export default {
start: startTimestamp
},
},
version: 2
// version: 2 // data accepts only one input to timestamp
}
24 changes: 24 additions & 0 deletions aggregators/7k-aggregator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import fetchURL from '../../utils/fetchURL';
import { FetchV2, SimpleAdapter } from '../../adapters/types';
import { CHAIN } from '../../helpers/chains';

const URL = 'https://statistic.7k.ag';

const fetch: FetchV2 = async ({ fromTimestamp, toTimestamp }) => {
const dailyVolume = await fetchURL(
`${URL}/volume-with-ts?from_timestamp=${fromTimestamp}&to_timestamp=${toTimestamp}`,
);
return { dailyVolume };
};

const adapter: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.SUI]: {
fetch,
start: 1719563120,
},
},
};

export default adapter;
35 changes: 35 additions & 0 deletions aggregators/akka/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import fetchURL from "../../utils/fetchURL"
import { FetchResult, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";

const URL = 'https://routerv2.akka.finance';
const endpoint = '/v2/1116/statistics/dappradar';
const startTimestamp = 1717200000;// 6/1/2024

interface IAPIResponse {
dailyVolume: string;
totalVolume: string;
}

const fetch = async (timestamp: number): Promise<FetchResult> => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
const { dailyVolume, totalVolume }: IAPIResponse = (await fetchURL(`${URL}${endpoint}`));
return {
dailyVolume,
totalVolume,
timestamp: dayTimestamp,
};
}

const adapter: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.CORE]: {
fetch,
start: startTimestamp,
},
},
};

export default adapter;
15 changes: 8 additions & 7 deletions aggregators/kanalabs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ export enum KanaChainID {
"solana" = 1,
"aptos" = 2,
"polygon" = 3,
"ethereum" = 4,
"bsc" = 5,
"klaytn" = 6,
"sui" = 8,
"Arbitrum" = 9,
"bsc" = 4,
"sui" = 5,
"ethereum" = 6,
"base" = 7,
"klaytn" = 8,
"zkSync" = 9,
"Avalanche" = 10,
"zkSync" = 11,
"base" = 12,
"Arbitrum" = 11,
"optimistic" = 12,
}

const fetch = (chain: KanaChainID) => async (timestamp: number) => {
Expand Down
35 changes: 35 additions & 0 deletions aggregators/magpie/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,41 @@ const fetch = async (timestamp: number, _: ChainBlocks, {chain}: FetchOptions):
runAtCurrTime: true,
start: 1662595200,
},
[CHAIN.SCROLL]: {
fetch: fetch,
runAtCurrTime: true,
start: 1662595200,
},
[CHAIN.MANTA]: {
fetch: fetch,
runAtCurrTime: true,
start: 1662595200,
},
[CHAIN.TAIKO]: {
fetch: fetch,
runAtCurrTime: true,
start: 1662595200,
},
[CHAIN.POLYGON_ZKEVM]: {
fetch: fetch,
runAtCurrTime: true,
start: 1662595200,
},
[CHAIN.BLAST]: {
fetch: fetch,
runAtCurrTime: true,
start: 1662595200,
},
[CHAIN.METIS]: {
fetch: fetch,
runAtCurrTime: true,
start: 1662595200,
},
[CHAIN.FANTOM]: {
fetch: fetch,
runAtCurrTime: true,
start: 1662595200,
},
},
isExpensiveAdapter: true,
};
Expand Down
49 changes: 22 additions & 27 deletions aggregators/swapgpt/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
import fetchURL from "../../utils/fetchURL"
import { SimpleAdapter } from "../../adapters/types";
import { httpGet } from "../../utils/fetchURL";
import { FetchOptions, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";



interface IVolumeall {
grouptimestamp: string;
amount: string;
totalVolumeUSD: string;
dailyVolumeUSD: Array<{
startDateTime: string;
dailyVolumeUSD: string;
}>
}

const baseUrl = "https://stats.panora.exchange";
const endpoint = "stats/getDefiLamaStats";


const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const historicalVolume: IVolumeall[] = (await fetchURL(`${baseUrl}/${endpoint}`))?.volumeInUsd
const totalVolume = historicalVolume
.filter(volItem => (new Date(volItem.grouptimestamp).getTime() / 1000) <= dayTimestamp)
.reduce((acc, { amount }) => acc + Number(amount), 0)

const dailyVolume = historicalVolume
.find(dayItem => (new Date(dayItem.grouptimestamp).getTime() / 1000) === dayTimestamp)?.amount
const baseUrl = "https://stats-api.panora.exchange";
const endpoint = "getDefiLlamaStats";

const fetch = async (options: FetchOptions) => {
const timestamp = options.startOfDay
const dateStr = new Date(timestamp * 1000).toISOString().split('T')[0];
const response: IVolumeall = (await httpGet(`${baseUrl}/${endpoint}`));
const totalVolume = response.totalVolumeUSD;
const dailyVolume = response.dailyVolumeUSD.find((d) => d.startDateTime.split('T')[0] === dateStr);
return {
totalVolume: `${totalVolume}`,
dailyVolume: dailyVolume ? `${dailyVolume}` : undefined,
timestamp: dayTimestamp,
};
dailyVolume: dailyVolume?.dailyVolumeUSD,
totalVolume
}
};

const adapter: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.APTOS]: {
fetch: fetch,
start: (new Date('2023-11-28T00:00:00.000Z').getTime() / 1000),
}
fetch,
start: 1701129600,
},
},
};

Expand Down
36 changes: 27 additions & 9 deletions dexs/aerodrome-slipstream/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,50 @@ const fetch = async (timestamp: number, _: any, { api, getLogs, createBalances,
let unfinished = true;

while (unfinished) {
const forSwaps: IForSwap[] = (await api.call({
const forSwapsUnfiltered: IForSwap[] = (await api.call({
target: gurar,
params: [chunkSize, currentOffset],
abi: abis.forSwaps,
chain: CHAIN.BASE,
})).filter(t => Number(t.type) > 0).map((e: any) => {
}));

const forSwaps: IForSwap[] = forSwapsUnfiltered.filter(t => Number(t.type) > 0).map((e: any) => {
return {
lp: e.lp,
token0: e.token0,
token1: e.token1,
pool_fee: e.pool_fee,
}
})
});

unfinished = forSwaps.length !== 0;
unfinished = forSwapsUnfiltered.length !== 0;
currentOffset += chunkSize;
allForSwaps.push(...forSwaps);
}

const targets = allForSwaps.map((forSwap: IForSwap) => forSwap.lp)

const logs: ILog[][] = await getLogs({
targets,
eventAbi: event_swap,
flatten: false,
})
let logs: ILog[][] = [];
const targetChunkSize = 5;
let currentTargetOffset = 0;
unfinished = true;

while (unfinished) {
let endOffset = currentTargetOffset + targetChunkSize;
if (endOffset >= targets.length) {
unfinished = false;
endOffset = targets.length;
}

let currentLogs: ILog[][] = await getLogs({
targets: targets.slice(currentTargetOffset, endOffset),
eventAbi: event_swap,
flatten: false,
})

logs.push(...currentLogs);
currentTargetOffset += targetChunkSize;
}

logs.forEach((logs: ILog[], idx: number) => {
const { token1, pool_fee } = allForSwaps[idx]
Expand Down
2 changes: 1 addition & 1 deletion dexs/apestore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const adapter: Adapter = {
fetch: async (options: FetchOptions): Promise<FetchResultV2> => {
const volumeData: VolumeInfo = await httpPost(URL, { date: options.startOfDay }, {
headers: {
"Authorization": "8690be69-3c53-4bc1-8e99-e4fe0472b757"
"Authorization": "92ff54fa-80b7-4f2c-bae1-f862ea7525ae"
},
});

Expand Down
Loading

0 comments on commit 14dc8dd

Please sign in to comment.