Skip to content

Commit

Permalink
Merge pull request #710 from DefiLlama/kyberswap-era-liean
Browse files Browse the repository at this point in the history
Kyberswap era liean
  • Loading branch information
dtmkeng authored Aug 5, 2023
2 parents 442606a + ccf9053 commit 70d2d98
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 40 deletions.
3 changes: 3 additions & 0 deletions dexs/kyberswap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const elasticEndpoints = elasticChains.reduce((acc, chain)=>({
ethereum: "https://api.thegraph.com/subgraphs/name/kybernetwork/kyberswap-elastic-mainnet",
arbitrum: "https://arbitrum-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-arbitrum",
polygon: "https://api.thegraph.com/subgraphs/name/kybernetwork/kyberswap-elastic-matic",
[CHAIN.LINEA]: "https://linea-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-linea"
} as any);
elasticEndpoints.fantom = "https://fantom-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-fantom"

Expand All @@ -76,6 +77,8 @@ const classicEndpoints = [...elasticChains, "aurora"].reduce((acc, chain)=>({
}), {
cronos: "https://cronos-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-exchange-cronos",
arbitrum: "https://arbitrum-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-exchange-arbitrum",
[CHAIN.ERA]: "https://zksync-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-exchange-zksync",
[CHAIN.LINEA]: "https://graph-query.linea.build/subgraphs/name/kybernetwork/kyberswap-classic-linea"
} as any);

const classicGraphs = getChainVolume({
Expand Down
35 changes: 0 additions & 35 deletions dexs/kyberswap/kyberswap-elastic-v2.ts

This file was deleted.

60 changes: 55 additions & 5 deletions fees/kyberswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,37 @@ const elasticEndpoints: TEndpoint = elasticChains.reduce((acc, chain) => ({
}), {
[CHAIN.ETHEREUM]: "https://api.thegraph.com/subgraphs/name/kybernetwork/kyberswap-elastic-mainnet",
[CHAIN.ARBITRUM]: "https://api.thegraph.com/subgraphs/name/kybernetwork/kyberswap-elastic-arbitrum-one",
[CHAIN.POLYGON]: "https://api.thegraph.com/subgraphs/name/kybernetwork/kyberswap-elastic-matic"
[CHAIN.POLYGON]: "https://api.thegraph.com/subgraphs/name/kybernetwork/kyberswap-elastic-matic",
[CHAIN.LINEA]: "https://linea-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-linea"
// [CHAIN.BITTORRENT]: "https://bttc-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-bttc",
// [CHAIN.CRONOS]: "https://cronos-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-cronos",
// [CHAIN.VELAS]: "https://velas-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-velas",
// [CHAIN.OASIS]: "https://oasis-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-oasis",
} as any);

const elasticEndpointsV2: TEndpoint = {
[CHAIN.ETHEREUM]: "https://ethereum-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-ethereum-legacy",
[CHAIN.BSC]: "https://bsc-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-bsc-legacy",
[CHAIN.POLYGON]: "https://bsc-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-bsc-legacy",
[CHAIN.AVAX]: "https://avalanche-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-avalanche-legacy",
[CHAIN.ARBITRUM]: "https://arbitrum-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-arbitrum-legacy",
[CHAIN.OPTIMISM]: "https://optimism-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-optimism-legacy",
[CHAIN.FANTOM]: "https://fantom-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-fantom-legacy",
[CHAIN.BITTORRENT]: "https://bttc-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-bttc-legacy",
[CHAIN.CRONOS]: "https://cronos-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-cronos-legacy",
// [CHAIN.VELAS]: "https://velas-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-velas-legacy",
// [CHAIN.OASIS]: "https://oasis-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-oasis-legacy",
};


const classicEndpoints: TEndpoint = [...elasticChains, "aurora"].reduce((acc, chain) => ({
[chain]: `https://api.thegraph.com/subgraphs/name/kybernetwork/kyberswap-exchange-${normalizeChain[chain] ?? chain}`,
...acc,
}), {
cronos: "https://cronos-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-exchange-cronos",
arbitrum: "https://arbitrum-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-exchange-arbitrum",
[CHAIN.ERA]: "https://zksync-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-exchange-zksync",
[CHAIN.LINEA]: "https://graph-query.linea.build/subgraphs/name/kybernetwork/kyberswap-classic-linea"
} as any);

const methodology = {
Expand All @@ -59,7 +81,7 @@ const methodology = {
}
}

const graphsElastic = (chain: Chain) => {
const graphsElasticV2 = (chain: Chain) => {
return async (timestamp: number): Promise<FetchResultFees> => {
const dateId = Math.floor(getTimestampAtStartOfDayUTC(timestamp) / 86400)

Expand All @@ -70,8 +92,9 @@ const graphsElastic = (chain: Chain) => {
}
}`;

const graphRes = await request(elasticEndpoints[chain], graphQuery);
const dailyFee = new BigNumber(graphRes.kyberSwapDayData.feesUSD);
if (!elasticEndpointsV2[chain]) return { timestamp };
const graphRes = await request(elasticEndpointsV2[chain], graphQuery);
const dailyFee = new BigNumber(graphRes.kyberSwapDayData?.feesUSD || '0');

return {
timestamp,
Expand All @@ -85,6 +108,33 @@ const graphsElastic = (chain: Chain) => {
};
};

const graphsElastic = (chain: Chain) => {
return async (timestamp: number): Promise<FetchResultFees> => {
const dateId = Math.floor(getTimestampAtStartOfDayUTC(timestamp) / 86400)

const graphQuery = gql
`{
kyberSwapDayData(id: ${dateId}) {
feesUSD
}
}`;

const graphRes = await request(elasticEndpoints[chain], graphQuery);
const elasticV2 = (await graphsElasticV2(chain)(timestamp))
const dailyFee = Number(graphRes.kyberSwapDayData?.feesUSD || '0') + Number(elasticV2?.dailyFees || '0');

return {
timestamp,
dailyUserFees: dailyFee.toString(),
dailyFees: dailyFee.toString(),
dailyRevenue: (dailyFee * 0.1).toString(),
dailyProtocolRevenue: "0",
dailyHoldersRevenue: (dailyFee * 0.1).toString(),
dailySupplySideRevenue: (dailyFee * 0.9).toString(),
};
};
};

interface IPoolData {
date: number;
dailyFeeUSD: string;
Expand All @@ -95,7 +145,7 @@ const graphsClassic = (chain: Chain) => {
const graphQuery = gql
`
{
poolDayDatas(first:1000) {
poolDayDatas(first:1000, orderBy:dailyFeeUSD, orderDirection: desc) {
date
dailyFeeUSD
}
Expand Down

0 comments on commit 70d2d98

Please sign in to comment.