Skip to content

Commit

Permalink
Merge branch 'DefiLlama:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
DJHellscream authored Aug 28, 2024
2 parents 6fae556 + 26686ff commit 76d6056
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 63 deletions.
90 changes: 73 additions & 17 deletions aggregator-derivatives/vooi/index.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,89 @@
import fetchURL from "../../utils/fetchURL";
import { FetchResult } from "../../adapters/types";
import { FetchResult, SimpleAdapter, FetchOptions } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";

const URL = "https://defilama-stats.vooi.workers.dev/";
const endpoint = "";
const startTimestamp = 1714608000; // 02.05.2024
const URL = "https://vooi-rebates.fly.dev/";
const endpoint = "defillama/volumes";
const startTimestampArbitrum = 1714608000; // 02.05.2024
const startTimestampBlast = 1719792000; // 01.07.2024
const startTimestampOpBNB = 1717200000; // 01.06.2024
const startTimestampBase = 1722470400; // 01.08.2024

const fetchArbitrum = async (options: FetchOptions): Promise<FetchResult> => {
const timestamp = options.toTimestamp
const fetchData = await fetchURL(`${URL}${endpoint}?ts=${timestamp}`)
const orderlyItem = fetchData.find(((item) => item.protocol == "orderly"))
if (!orderlyItem) return {dailyVolume: 0, totalVolume: 0, timestamp}
const dailyVolume = orderlyItem.dailyVolume
const totalVolume = orderlyItem.totalVolume
return {
dailyVolume,
totalVolume,
timestamp
};
};

interface IAPIResponse {
dailyVolume: string;
totalVolume: string;
}
const fetch = async (timestamp: number): Promise<FetchResult> => {
const { dailyVolume, totalVolume }: IAPIResponse = (
(await fetchURL(`${URL}${endpoint}?ts=${timestamp}`)).data
);
const fetchBlast = async (options: FetchOptions): Promise<FetchResult> => {
const timestamp = options.toTimestamp
const fetchData = await fetchURL(`${URL}${endpoint}?ts=${timestamp}`)
const synfuturesItem = fetchData.find(((item) => item.protocol == "synfutures" && item.network == "blast"))
if (!synfuturesItem) return {dailyVolume: 0, totalVolume: 0, timestamp}
const dailyVolume = synfuturesItem.dailyVolume
const totalVolume = synfuturesItem.totalVolume
return {
timestamp,
dailyVolume,
totalVolume,
timestamp
};
};

export default {
const fetchBase = async (options: FetchOptions): Promise<FetchResult> => {
const timestamp = options.toTimestamp
const fetchData = await fetchURL(`${URL}${endpoint}?ts=${timestamp}`)
const synfuturesItem = fetchData.find(((item) => item.protocol == "synfutures" && item.network == "base"))
if (!synfuturesItem) return {dailyVolume: 0, totalVolume: 0, timestamp}
const dailyVolume = synfuturesItem.dailyVolume
const totalVolume = synfuturesItem.totalVolume
return {
dailyVolume,
totalVolume,
timestamp
};
};

const fetchOpBNB = async (options: any): Promise<FetchResult> => {
const timestamp = options.toTimestamp
const fetchData = await fetchURL(`${URL}${endpoint}?ts=${timestamp}`)
const kiloexItem = fetchData.find(((item) => item.protocol == "kiloex"))
if (!kiloexItem) return {dailyVolume: 0, totalVolume: 0, timestamp}
const dailyVolume = kiloexItem.dailyVolume
const totalVolume = kiloexItem.totalVolume
return {
dailyVolume,
totalVolume,
timestamp
};
};

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.ARBITRUM]: {
fetch: fetch,
start: startTimestamp
fetch: fetchArbitrum,
start: startTimestampArbitrum
},
[CHAIN.BLAST]: {
fetch: fetchBlast,
start: startTimestampBlast
},
[CHAIN.OP_BNB]: {
fetch: fetchOpBNB,
start: startTimestampOpBNB
},
[CHAIN.BASE]: {
fetch: fetchBase,
start: startTimestampBase
},
},
// version: 2 // data accepts only one input to timestamp
version: 2
}
export default adapter
84 changes: 43 additions & 41 deletions dexs/fulcrom-finance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const endpoints: { [key: string]: string } = {
"https://graph.cronoslabs.com/subgraphs/name/fulcrom/stats-prod",
[CHAIN.ERA]:
"https://api.studio.thegraph.com/query/52869/stats-prod/version/latest",
[CHAIN.CRONOS_ZKEVM]: "https://api.goldsky.com/api/public/project_clwrfupe2elf301wlhnd7bvva/subgraphs/fulcrom-stats-mainnet/prod/gn"
};

const historicalDataSwap = gql`
Expand Down Expand Up @@ -39,51 +40,52 @@ interface IGraphResponse {

const getFetch =
(query: string) =>
(chain: string): Fetch =>
async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(
new Date(timestamp * 1000)
);
const dailyData: IGraphResponse = await request(endpoints[chain], query, {
id: "daily:" + String(dayTimestamp),
period: "daily",
});
const totalData: IGraphResponse = await request(endpoints[chain], query, {
id: "total",
period: "total",
});
(chain: string): Fetch =>
async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(
new Date(timestamp * 1000)
);
const dailyData: IGraphResponse = await request(endpoints[chain], query, {
id: "daily:" + String(dayTimestamp),
period: "daily",
});
const totalData: IGraphResponse = await request(endpoints[chain], query, {
id: "total",
period: "total",
});

return {
timestamp: dayTimestamp,
dailyVolume:
dailyData.volumeStats.length == 1
? String(
Number(
Object.values(dailyData.volumeStats[0]).reduce((sum, element) =>
String(Number(sum) + Number(element))
)
) *
return {
timestamp: dayTimestamp,
dailyVolume:
dailyData.volumeStats.length == 1
? String(
Number(
Object.values(dailyData.volumeStats[0]).reduce((sum, element) =>
String(Number(sum) + Number(element))
)
) *
10 ** -30
)
: undefined,
totalVolume:
totalData.volumeStats.length == 1
? String(
Number(
Object.values(totalData.volumeStats[0]).reduce((sum, element) =>
String(Number(sum) + Number(element))
)
) *
)
: undefined,
totalVolume:
totalData.volumeStats.length == 1
? String(
Number(
Object.values(totalData.volumeStats[0]).reduce((sum, element) =>
String(Number(sum) + Number(element))
)
) *
10 ** -30
)
: undefined,
};
};
)
: undefined,
};
};

const startTimestamps: { [chain: string]: number } = {
[CHAIN.CRONOS]: 1677470400,
[CHAIN.ERA]: 1696496400,
};
const startTimestamps: { [chain: string]: number } = {
[CHAIN.CRONOS]: 1677470400,
[CHAIN.ERA]: 1696496400,
[CHAIN.CRONOS_ZKEVM]: 1723698700,
};

const adapter: BreakdownAdapter = {
breakdown: {
Expand Down
6 changes: 3 additions & 3 deletions dexs/gmx-v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import request, { gql } from "graphql-request";
import { BreakdownAdapter, Fetch, SimpleAdapter } from "../../adapters/types";
import { BreakdownAdapter, Fetch, FetchOptions, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";

Expand Down Expand Up @@ -31,8 +31,8 @@ interface IGraphResponse {
}>
}

const getFetch = (query: string)=> (chain: string): Fetch => async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date((timestamp * 1000)))
const getFetch = (query: string)=> (chain: string): Fetch => async (_tt: number, _t: any, options: FetchOptions) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date((options.startOfDay * 1000)))
const dailyData: IGraphResponse = await request(endpoints[chain], query, {
id: '1d:' + String(dayTimestamp),
period: '1d',
Expand Down
4 changes: 4 additions & 0 deletions dexs/jellyverse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const v2Graphs = (chain: Chain) => {
return acc;
}, { dailyVolume: 0, dailyFees: 0 });

if (dailyVolume > 1_000_000_000) {
return {}
}

return {
dailyVolume: dailyVolume.toString(),
dailyFees: dailyFees.toString(),
Expand Down
8 changes: 8 additions & 0 deletions fees/fulcrom-finance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const endpoints = {
"https://graph.cronoslabs.com/subgraphs/name/fulcrom/stats-prod",
[CHAIN.ERA]:
"https://api.studio.thegraph.com/query/52869/stats-prod/version/latest",
[CHAIN.CRONOS_ZKEVM]: "https://api.goldsky.com/api/public/project_clwrfupe2elf301wlhnd7bvva/subgraphs/fulcrom-stats-mainnet/prod/gn"
};

const methodology = {
Expand Down Expand Up @@ -99,6 +100,13 @@ const adapter: Adapter = {
methodology,
},
},
[CHAIN.CRONOS_ZKEVM]: {
fetch: graphs(endpoints)(CHAIN.CRONOS_ZKEVM),
start: 1723698700,
meta: {
methodology,
},
},
},
};

Expand Down
3 changes: 2 additions & 1 deletion helpers/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ export enum CHAIN {
ZKLINK = "zklink",
DEXALOT = "dexalot",
IMMUTABLEX = "immutablex",
CHAINFLIP = "chainflip"
CHAINFLIP = "chainflip",
CRONOS_ZKEVM = "cronos_zkevm",
}

// Don´t use
Expand Down
3 changes: 2 additions & 1 deletion helpers/coreAssets.json
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,8 @@
"CELER_DAI": "0x8d87a65ba30e09357fa2edea2c80dbac296e5dec2b18287113500b902942929d::celer_coin_manager::DaiCoin",
"CELER_ETH": "0x8d87a65ba30e09357fa2edea2c80dbac296e5dec2b18287113500b902942929d::celer_coin_manager::WethCoin",
"CELER_WBTC": "0x8d87a65ba30e09357fa2edea2c80dbac296e5dec2b18287113500b902942929d::celer_coin_manager::WbtcCoin",
"amAPT": "0x111ae3e5bc816a5e63c2da97d0aa3886519e0cd5e4b046659fa35796bd11542a::amapt_token::AmnisApt"
"amAPT": "0x111ae3e5bc816a5e63c2da97d0aa3886519e0cd5e4b046659fa35796bd11542a::amapt_token::AmnisApt",
"aBTC": "0x4e1854f6d332c9525e258fb6e66f84b6af8aba687bbcb832a24768c4e175feec::abtc::ABTC"
},
"dogechain": {
"WWDOGE": "0xb7ddc6414bf4f5515b52d8bdd69973ae205ff101",
Expand Down
61 changes: 61 additions & 0 deletions protocols/magicsea-lb/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { ChainBlocks, FetchOptions, IJSON, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { addOneToken } from "../../helpers/prices";
import { filterPools } from "../../helpers/uniswap";

const event_swap = 'event Swap(address indexed sender, address indexed to, uint24 id, bytes32 amountsIn, bytes32 amountsOut, uint24 volatilityAccumulator, bytes32 totalFees, bytes32 protocolFees)';
const FACTORY_ADDRESS = '0x8Cce20D17aB9C6F60574e678ca96711D907fD08c';

type TABI = {
[k: string]: string;
}
const ABIs: TABI = {
"getNumberOfLBPairs": "uint256:getNumberOfLBPairs",
"getLBPairAtIndex": "function getLBPairAtIndex(uint256 index) view returns (address lbPair)"
}

const fetch: any = async (timestamp: number, _: ChainBlocks, { getLogs, api, createBalances }: FetchOptions) => {
const dailyVolume = createBalances();
const dailyFees = createBalances();
const dailyRevenue = createBalances();
const lpTokens = await api.fetchList({ lengthAbi: ABIs.getNumberOfLBPairs, itemAbi: ABIs.getLBPairAtIndex, target: FACTORY_ADDRESS })
const [tokens0, tokens1] = await Promise.all(['address:getTokenX', 'address:getTokenY'].map((abi: string) => api.multiCall({ abi, calls: lpTokens })));


const pairObject: IJSON<string[]> = {}
lpTokens.forEach((pair: string, i: number) => {
pairObject[pair] = [tokens0[i], tokens1[i]]
})

// filter out the pairs with less than 1000 USD pooled value
const filteredPairs = await filterPools({ api: api, pairs: pairObject, createBalances: createBalances })
await Promise.all(Object.keys(filteredPairs).map(async (pair) => {
const [token0, token1] = pairObject[pair]
const logs = await getLogs({ target: pair, eventAbi: event_swap })
logs.forEach(log => {
const amountInX = Number('0x' + '0'.repeat(32) + log.amountsOut.replace('0x', '').slice(0, 32))
const amountInY = Number('0x' + '0'.repeat(32) + log.amountsOut.replace('0x', '').slice(32, 64))
dailyVolume.add(token1, amountInX);
dailyVolume.add(token0, amountInY);

const protocolFeesY = Number('0x' + log.protocolFees.replace('0x', '').slice(0, 32))
const protocolFeesX = Number('0x' + log.protocolFees.replace('0x', '').slice(32, 64))
const totalFeesY = Number('0x' + log.totalFees.replace('0x', '').slice(0, 32));
const totalFeesX = Number('0x' + log.totalFees.replace('0x', '').slice(32, 64));
dailyFees.add(token0, totalFeesX )
dailyFees.add(token1, totalFeesY )
dailyRevenue.add(token0, protocolFeesX)
dailyRevenue.add(token1, protocolFeesY)
})
}))

return { dailyVolume, dailyFees, dailyRevenue, timestamp };
}

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.IOTAEVM]: { fetch, start: 1681130543, },
}
};

export default adapter;

0 comments on commit 76d6056

Please sign in to comment.