Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: vertex supports sonic #2328

Merged
merged 1 commit into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 11 additions & 4 deletions fees/vertex-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const archiveArbitrumUrl = "https://archive.prod.vertexprotocol.com/v1";
const archiveMantleUrl = "https://archive.mantle-prod.vertexprotocol.com/v1";
const archiveSeiUrl = "https://archive.sei-prod.vertexprotocol.com/v1";
const archiveBaseUrl = "https://archive.base-prod.vertexprotocol.com/v1";
const archiveSonicUrl = "https://archive.sonic-prod.vertexprotocol.com/v1";

type TURL = {
[s: string]: string;
Expand All @@ -40,6 +41,7 @@ const url: TURL = {
[CHAIN.MANTLE]: archiveMantleUrl,
[CHAIN.SEI]: archiveSeiUrl,
[CHAIN.BASE]: archiveBaseUrl,
[CHAIN.SONIC]: archiveSonicUrl,
};

const query = async (
Expand Down Expand Up @@ -174,22 +176,27 @@ const adapter: Adapter = {
[CHAIN.ARBITRUM]: {
fetch: fetch,
runAtCurrTime: true,
start: '2023-04-26',
start: "2023-04-26",
},
[CHAIN.MANTLE]: {
fetch: fetch,
runAtCurrTime: true,
start: '2023-04-26',
start: "2023-04-26",
},
[CHAIN.SEI]: {
fetch: fetch,
runAtCurrTime: true,
start: '2024-08-13',
start: "2024-08-13",
},
[CHAIN.BASE]: {
fetch: fetch,
runAtCurrTime: true,
start: '2024-09-04',
start: "2024-09-04",
},
[CHAIN.SONIC]: {
fetch: fetch,
runAtCurrTime: true,
start: "2024-12-18",
},
},
};
Expand Down
Loading