Skip to content

Commit

Permalink
vertex supports sonic
Browse files Browse the repository at this point in the history
  • Loading branch information
yruej301 committed Jan 17, 2025
1 parent 9cecc29 commit 9c1daeb
Show file tree
Hide file tree
Showing 2 changed files with 2,595 additions and 34 deletions.
93 changes: 59 additions & 34 deletions dexs/vertex-protocol/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const archiveSeiUrl = "https://archive.sei-prod.vertexprotocol.com/v1";
const gatewayBaseUrl = "https://gateway.base-prod.vertexprotocol.com/v1";
const archiveBaseUrl = "https://archive.base-prod.vertexprotocol.com/v1";

const gatewaySonicUrl = "https://gateway.sonic-prod.vertexprotocol.com/v1";
const archiveSonicUrl = "https://archive.sonic-prod.vertexprotocol.com/v1";

type TURL = {
[s: string]: {
gateway: string;
Expand All @@ -43,6 +46,10 @@ const url: TURL = {
gateway: gatewaySeiUrl,
archive: archiveSeiUrl,
},
[CHAIN.SONIC]: {
gateway: gatewaySonicUrl,
archive: archiveSonicUrl
}
};

const fetchValidSymbols = async (
Expand Down Expand Up @@ -77,40 +84,49 @@ const computeVolume = async (
productIds: number[],
fetchOptions: FetchOptions
) => {
const snapshots = (
await httpPost(url[fetchOptions.chain].archive, {
market_snapshots: {
interval: {
count: 2,
granularity: 86400,
max_time: timestamp,
if (productIds.length > 0) {
const snapshots = (
await httpPost(url[fetchOptions.chain].archive, {
market_snapshots: {
interval: {
count: 2,
granularity: 86400,
max_time: timestamp,
},
product_ids: productIds,
},
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 ? `${dailyVolume}` : undefined,
timestamp: timestamp,
};
})
).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 ? `${dailyVolume}` : undefined,
timestamp: timestamp,
};
} else {
return {
totalVolume: undefined,
dailyVolume: undefined,
timestamp: timestamp,
};
}

};

const fetchSpots = async (
Expand All @@ -119,7 +135,7 @@ const fetchSpots = async (
fetchOptions: FetchOptions
) => {
const spotProductIds = (await fetchProducts(fetchOptions)).spot_products;
return await computeVolume(timeStamp, spotProductIds, fetchOptions);
return computeVolume(timeStamp, spotProductIds, fetchOptions);
};

const fetchPerps = async (
Expand All @@ -140,6 +156,7 @@ const fetchPerps = async (
const startTime = 1682514000;
const seiStartTime = 1723547681;
const baseStartTime = 1725476671;
const sonicStartTime = 1734543997;

const adapter: BreakdownAdapter = {
breakdown: {
Expand All @@ -160,6 +177,10 @@ const adapter: BreakdownAdapter = {
fetch: fetchSpots,
start: baseStartTime,
},
[CHAIN.SONIC]: {
fetch: fetchSpots,
start: sonicStartTime,
}
},
derivatives: {
[CHAIN.ARBITRUM]: {
Expand All @@ -178,6 +199,10 @@ const adapter: BreakdownAdapter = {
fetch: fetchPerps,
start: baseStartTime,
},
[CHAIN.SONIC]: {
fetch: fetchPerps,
start: sonicStartTime
}
},
},
};
Expand Down
Loading

0 comments on commit 9c1daeb

Please sign in to comment.