Skip to content

Commit

Permalink
Merge pull request DefiLlama#3 from DefiLlama/master
Browse files Browse the repository at this point in the history
Sync with origin
  • Loading branch information
silvercondor authored Mar 22, 2024
2 parents 684cc6f + f2d422e commit 17f8188
Show file tree
Hide file tree
Showing 15 changed files with 673 additions and 74 deletions.
12 changes: 12 additions & 0 deletions dexs/archly-finance-v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const adapter: SimpleAdapter = {
fetch: getDexVolumeExports({ chain: CHAIN.FANTOM, factory: FACTORY_ADDRESS }),
start: 1700784000,
},
[CHAIN.BLAST]: {
fetch: getDexVolumeExports({ chain: CHAIN.BLAST, factory: FACTORY_ADDRESS }),
start: 1710720000,
},
[CHAIN.BSC]: {
fetch: getDexVolumeExports({ chain: CHAIN.FANTOM, factory: FACTORY_ADDRESS }),
start: 1700784000,
Expand All @@ -34,6 +38,14 @@ const adapter: SimpleAdapter = {
fetch: getDexVolumeExports({ chain: CHAIN.FANTOM, factory: FACTORY_ADDRESS }),
start: 1700784000,
},
[CHAIN.FILECOIN]: {
fetch: getDexVolumeExports({ chain: CHAIN.FILECOIN, factory: FACTORY_ADDRESS }),
start: 1710979200,
},
[CHAIN.FRAXTAL]: {
fetch: getDexVolumeExports({ chain: CHAIN.FRAXTAL, factory: FACTORY_ADDRESS }),
start: 1710720000,
},
[CHAIN.KAVA]: {
fetch: getDexVolumeExports({ chain: CHAIN.FANTOM, factory: FACTORY_ADDRESS }),
start: 1700784000,
Expand Down
107 changes: 107 additions & 0 deletions dexs/blitz/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { BreakdownAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { httpGet, httpPost } from "../../utils/fetchURL";

interface IProducts {
spot_products: number[];
perp_products: number[];
margined_products: number[];
}

const gatewayBaseUrl = "https://gateway.blast-prod.vertexprotocol.com/v1";
const archiveBaseUrl = "https://archive.blast-prod.vertexprotocol.com/v1";

const fetchValidSymbols = async (): Promise<number[]> => {
const symbols = await httpGet(`${gatewayBaseUrl}/symbols`);
return symbols.map((product: { product_id: number }) => product.product_id);
};

const fetchProducts = async (): Promise<IProducts> => {
const validSymbols = await fetchValidSymbols();
const allProducts = (
await httpGet(`${gatewayBaseUrl}/query?type=all_products`)
).data;
return {
spot_products: allProducts.spot_products
.map((product: { product_id: number }) => product.product_id)
.filter((id: number) => validSymbols.includes(id) && id > 0),
perp_products: allProducts.perp_products
.map((product: { product_id: number }) => product.product_id)
.filter((id: number) => validSymbols.includes(id)),
margined_products: allProducts.spot_products
.map((product: { product_id: number }) => product.product_id)
.filter((id: number) => validSymbols.includes(id) && id > 0),
};
};

const computeVolume = async (timestamp: number, productIds: number[]) => {
const snapshots = (
await httpPost(archiveBaseUrl, {
market_snapshots: {
interval: {
count: 2,
granularity: 86400,
max_time: timestamp,
},
product_ids: productIds,
},
})
).snapshots;
const lastCumulativeVolumes: Record<string, string> =
snapshots[0].cumulative_volumes;
const prevCumulativeVolumes: Record<string, string> =
snapshots[1].cumulative_volumes;
const totalVolume = Number(
Object.values(lastCumulativeVolumes).reduce(
(acc, current) => acc + BigInt(current),
BigInt(0)
) / BigInt(10 ** 18)
);
const totalVolumeOneDayAgo = Number(
Object.values(prevCumulativeVolumes).reduce(
(acc, current) => acc + BigInt(current),
BigInt(0)
) / BigInt(10 ** 18)
);
const dailyVolume = totalVolume - totalVolumeOneDayAgo;
return {
totalVolume: totalVolume ? `${totalVolume}` : undefined,
dailyVolume: dailyVolume !== undefined ? `${dailyVolume}` : undefined,
timestamp: timestamp,
};
};

const fetchSpots = async (timeStamp: number) => {
const spotProductIds = (await fetchProducts()).spot_products;
return await computeVolume(timeStamp, spotProductIds);
};

const fetchPerps = async (timeStamp: number) => {
const perpProductIds = (await fetchProducts()).perp_products;
const marginedProductIds = (await fetchProducts()).margined_products;
return await computeVolume(
timeStamp,
perpProductIds.concat(marginedProductIds)
);
};

const startTime = 1710259200;

const adapter: BreakdownAdapter = {
breakdown: {
swap: {
[CHAIN.BLAST]: {
fetch: fetchSpots,
start: startTime,
},
},
derivatives: {
[CHAIN.BLAST]: {
fetch: fetchPerps,
start: startTime,
},
},
},
};

export default adapter;
59 changes: 59 additions & 0 deletions dexs/cauldron/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// This adaptor uses the Riftenlabs Indexer API to query for volume.
//
// This indexer is open source (AGPLv3) and available at:
// https://gitlab.com/riftenlabs/riftenlabs-indexer

import { FetchOptions, FetchResult, SimpleAdapter } from "../../adapters/types";
import fetchURL from "../../utils/fetchURL";
import { CHAIN } from "../../helpers/chains";

const INDEXER_URL = "https://indexer.cauldron.quest";

const methodology = {
Volume: "Scrape the blockchain and filter for spent transaction outputs that match the cauldron contract's redeem script. Check if the transaction has an output with a locking script that matches the redeem script in the input. A match on locking script means the funds are still locked in the DEX contract. Aggregate the difference of funds in contract utxos as trade volume.",
Fees: "N/A",
Revenue: "N/A",
}

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.BITCOIN_CASH]: {
fetch: fetchCauldronVolume,
start: 1688198180,
meta: {
methodology
}
},
},
};

export async function fetchCauldronVolume(
timestamp: number, _, options: FetchOptions
): Promise<FetchResult> {
const endpoint = `${INDEXER_URL}/cauldron/contract/volume?end=${timestamp}`;
const volume = await fetchURL(endpoint)

const total_sats = volume.reduce((acc, token) => {
return acc + BigInt(token.total_sats)
}, BigInt(0));

const daily_sats = volume.reduce((acc, token) => {
return acc + BigInt(token.one_day_sats)
}, BigInt(0));

const COIN = 100000000n;

const dailyVolume = options.createBalances();
const totalVolume = options.createBalances();

dailyVolume.addCGToken('bitcoin-cash', Number(daily_sats / COIN));
totalVolume.addCGToken('bitcoin-cash', Number(total_sats / COIN));

return {
timestamp,
dailyVolume,
totalVolume,
};
}

export default adapter;
2 changes: 1 addition & 1 deletion dexs/kinetix-derivatives-v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Chain } from "@defillama/sdk/build/general";
import request, { gql } from "graphql-request";

const kinetixPerpsV2Subgraph =
"https://kava-graph-node.metavault.trade/subgraphs/name/kinetixfi/perpv2";
"https://kava-graph-node.metavault.trade/subgraphs/name/kinetixfi/kava-trade";

interface IReferralRecord {
volume: string; // Assuming volume is a string that represents a number
Expand Down
2 changes: 1 addition & 1 deletion dexs/maia-v3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const v3Graphs = getGraphDimensions({
},
feesPercent: {
type: "fees",
ProtocolRevenue: 10, // 10% of fees are going to LPs
ProtocolRevenue: 10, // 10% of fees are going to protocol
HoldersRevenue: 0,
UserFees: 100, // User fees are 100% of collected fees
SupplySideRevenue: 90, // 90% of fees are going to LPs
Expand Down
75 changes: 75 additions & 0 deletions dexs/myx-finance/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import request, { gql } from "graphql-request";
import { ChainEndpoints, Fetch, FetchOptions, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";


// Subgraphs endpoints
const endpoints: ChainEndpoints = {
[CHAIN.ARBITRUM]: "https://subgraph-arb.myx.finance/subgraphs/name/myx-subgraph",
[CHAIN.LINEA]: "https://subgraph-linea.myx.finance/subgraphs/name/myx-subgraph",
}

const methodology = {
TotalVolume: "Total Volume from the sum of the open/close/liquidation of positions.",
DailyVolume: "Daily Volume from the sum of the open/close/liquidation of positions.",
}

interface IGraphResponse {
tradeVolume: {
volume: string,
id: 'string'
}
}

const getFetch = async (optios: FetchOptions) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date((optios.endTimestamp * 1000)))

const dailyData: IGraphResponse = await request(endpoints[optios.chain], gql`
query MyQuery {
tradeVolume(id: "${dayTimestamp}") {
volume
id
}
}
`)

const totalData: IGraphResponse = await request(endpoints[optios.chain], gql`
query MyQuery {
tradeVolume(id: "global") {
volume
id
}
}`
)

return {
timestamp: dayTimestamp,
dailyVolume: dailyData.tradeVolume?.volume || "0",
totalVolume: totalData.tradeVolume?.volume || "0",
}
}


const startTimestamps: { [chain: string]: number } = {
[CHAIN.ARBITRUM]: 1706659200,
[CHAIN.LINEA]: 1708473600,
}

const adapter: SimpleAdapter = {
version: 2,
adapter: Object.keys(endpoints).reduce((acc, chain) => {
return {
...acc,
[chain]: {
fetch: getFetch,
start: startTimestamps[chain],
meta: {
methodology: methodology,
},
}
}
}, {})
}

export default adapter;
39 changes: 21 additions & 18 deletions dexs/traderjoe/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Chain } from "@defillama/sdk/build/general";
import { BreakdownAdapter, FetchResultVolume } from "../../adapters/types";
import { BreakdownAdapter, FetchOptions, FetchResultVolume } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getChainVolume, getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";
import fetchURL from "../../utils/fetchURL";
Expand All @@ -15,28 +15,27 @@ type TEndpoint = {
const endpointsV2: TEndpoint = {
[CHAIN.AVAX]: "https://api.thegraph.com/subgraphs/name/traderjoe-xyz/joe-v2",
[CHAIN.ARBITRUM]: "https://barn.traderjoexyz.com/v1/dex/analytics/arbitrum?startTime=1672012800&aggregateBy=daily",
[CHAIN.BSC]: "https://barn.traderjoexyz.com/v1/dex/analytics/binance?startTime=1677801600&aggregateBy=daily"
[CHAIN.BSC]: "https://barn.traderjoexyz.com/v1/dex/analytics/binance?startTime=1677801600&aggregateBy=daily",
[CHAIN.ETHEREUM]: "https://barn.traderjoexyz.com/v1/dex/analytics/ethereum?startTime=1695513600&aggregateBy=daily"
}

interface IVolume {
timestamp: number;
volumeUsd: number;
}
const fetchV2 = (chain: Chain) => {
return async (timestamp: number): Promise<FetchResultVolume> => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const historicalVolume: IVolume[] = (await fetchURL(endpointsV2[chain]));
const totalVolume = historicalVolume
.filter(volItem => volItem.timestamp <= dayTimestamp)
.reduce((acc, { volumeUsd }) => acc + Number(volumeUsd), 0)
const fetchV2 = async (options: FetchOptions): Promise<FetchResultVolume> => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(options.endTimestamp * 1000))
const historicalVolume: IVolume[] = (await fetchURL(endpointsV2[options.chain]));
const totalVolume = historicalVolume
.filter(volItem => volItem.timestamp <= dayTimestamp)
.reduce((acc, { volumeUsd }) => acc + Number(volumeUsd), 0)

const dailyVolume = historicalVolume
.find(dayItem => dayItem.timestamp === dayTimestamp)?.volumeUsd
return {
totalVolume: `${totalVolume}`,
dailyVolume: dailyVolume !== undefined ? `${dailyVolume}` : undefined,
timestamp: dayTimestamp,
}
const dailyVolume = historicalVolume
.find(dayItem => dayItem.timestamp === dayTimestamp)?.volumeUsd
return {
totalVolume: `${totalVolume}`,
dailyVolume: dailyVolume !== undefined ? `${dailyVolume}` : undefined,
timestamp: dayTimestamp,
}
}

Expand Down Expand Up @@ -90,13 +89,17 @@ const adapter: BreakdownAdapter = {
start: 1668556800
},
[CHAIN.ARBITRUM]: {
fetch: fetchV2(CHAIN.ARBITRUM),
fetch: fetchV2,
start: 1672012800
},
[CHAIN.BSC]: {
fetch: fetchV2(CHAIN.BSC),
fetch: fetchV2,
start: 1677801600
},
[CHAIN.ETHEREUM]: {
fetch: fetchV2,
start: 1695513600
}
}
},
};
Expand Down
Loading

0 comments on commit 17f8188

Please sign in to comment.