forked from DefiLlama/dimension-adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DefiLlama#3 from DefiLlama/master
Sync with origin
- Loading branch information
Showing
15 changed files
with
673 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.