Skip to content

Commit 7f76091

Browse files
KPHEMRAJnoateden
andauthored
track ethereal perp volume,fee and oi (#4517)
* track ethereal perp volume and oi * small fix * track ethereal fee * move ethereal volume calculation to onchain * smol fix * refactor --------- Co-authored-by: Eden <[email protected]>
1 parent b474cb8 commit 7f76091

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

dexs/ethereal-dex/index.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { SimpleAdapter, FetchOptions, FetchResult } from "../../adapters/types";
2+
import { CHAIN } from "../../helpers/chains";
3+
4+
const FEE_ACCURED_EVENT = "event FeeAccrued(address indexed account, bytes32 indexed subaccount, address token, uint256 feeAmount, uint256 balance, uint64 messageIdx)";
5+
6+
const ORDER_MATCHED_EVENT = "event PerpOrderMatched(uint32 indexed productId, address indexed maker, address indexed taker, bytes32 makerSubaccount, bytes32 takerSubaccount, uint8 makerSide, uint8 takerSide, uint128 fillQuantity, uint128 price, uint64 messageIdx)";
7+
8+
const EXCHANGE_GATEWAY = "0xB3cDC82035C495c484C9fF11eD5f3Ff6d342e3cc";
9+
10+
async function fetch(options: FetchOptions): Promise<FetchResult> {
11+
const dailyFees = options.createBalances();
12+
const dailyVolume = options.createBalances();
13+
14+
const feeAccuredLogs = await options.getLogs({
15+
target: EXCHANGE_GATEWAY,
16+
eventAbi: FEE_ACCURED_EVENT
17+
});
18+
19+
const orderMatchedLogs = await options.getLogs({
20+
target: EXCHANGE_GATEWAY,
21+
eventAbi: ORDER_MATCHED_EVENT
22+
});
23+
24+
feeAccuredLogs.forEach((fee: any) => {
25+
dailyFees.addCGToken("ethena-usde", Number(fee.feeAmount) / 1e9);
26+
});
27+
28+
orderMatchedLogs.forEach((order:any)=>{
29+
dailyVolume.addCGToken("ethena-usde",(Number(order.fillQuantity)/1e9)*(Number(order.price)/1e9));
30+
});
31+
32+
return {
33+
dailyVolume,
34+
dailyFees,
35+
dailyRevenue: dailyFees,
36+
dailyProtocolRevenue: dailyFees,
37+
}
38+
}
39+
40+
const methodology = {
41+
Volume: "Ethereal perp trade volume",
42+
Fees: "All trading fees paid by users",
43+
Revenue: "All the fees is revenue",
44+
ProtocolRevenue: "All the revenue goes to protocol",
45+
}
46+
47+
const adapter: SimpleAdapter = {
48+
version: 2,
49+
fetch,
50+
chains: [CHAIN.ETHEREAL],
51+
methodology,
52+
start: '2025-10-21'
53+
}
54+
55+
export default adapter;

helpers/chains.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,5 @@ export enum CHAIN {
272272
HIBACHI = "hibachi",
273273
SATORI = "satori",
274274
SHIBARIUM = "shibarium",
275+
ETHEREAL = "ethereal",
275276
}

open-interest/ethereal-oi.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { SimpleAdapter, FetchResult, FetchOptions } from "../adapters/types";
2+
import { CHAIN } from "../helpers/chains";
3+
import fetchUrl from "../utils/fetchURL";
4+
5+
async function fetch(_a: any, _b: any, _c: FetchOptions): Promise<FetchResult> {
6+
7+
const tradeData = (await fetchUrl("https://api.ethereal.trade/v1/product")).data;
8+
9+
const marketPrice = (await fetchUrl(`https://api.ethereal.trade/v1/product/market-price?productIds=${tradeData.map((market: any) => market.id).join('&productIds=')}`)).data;
10+
11+
const openInterestAtEnd = tradeData.reduce((acc: number, market: any) => {
12+
const price = + ((marketPrice.find((priceEntry: any) => market.id === priceEntry.productId))?.oraclePrice || 0);
13+
acc+= price * +(market.openInterest || 0);
14+
return acc;
15+
}, 0);
16+
17+
return {
18+
openInterestAtEnd,
19+
}
20+
}
21+
22+
const adapter: SimpleAdapter = {
23+
chains: [CHAIN.ETHEREAL],
24+
fetch,
25+
runAtCurrTime: true
26+
}
27+
28+
export default adapter;

0 commit comments

Comments
 (0)