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

feat: add hiveswap pro #1331

Closed
wants to merge 1 commit into from
Closed
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
59 changes: 59 additions & 0 deletions dexs/hiveswap-pro/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import fetchURL from "../../utils/fetchURL"
import customBackfill from "../../helpers/customBackfill";
import {getUniqStartOfTodayTimestamp} from "../../helpers/getUniSubgraphVolume";

const mapChainId = 22776
const historicalVolumeEndpoint = (page: number) => `https://api-dass.izumi.finance/api/v1/izi_swap/summary_record/?chain_id=${mapChainId}&type=4&page_size=60&order_by=-time&&page=${page}`

interface IVolumeall {
volDay: number;
chainId: number;
timestamp: number;
}

type TAdapter = {
[key:string]: any;
};

const fetch = () => {
return async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
let isSuccess = true;
let page = 1;
const historical: IVolumeall[] = [];
while (isSuccess) {
const response = (await fetchURL(historicalVolumeEndpoint(page)));
if (response.is_success){
Array.prototype.push.apply(historical, response.data);
page += 1;
} else {
isSuccess = false;
};
};
const historicalVolume = historical.filter(e => e.chainId === mapChainId);
const totalVolume = historicalVolume
.filter(volItem => (new Date(volItem.timestamp).getTime()) <= dayTimestamp)
.reduce((acc, { volDay }) => acc + Number(volDay), 0)

const dailyVolume = historicalVolume
.find(dayItem => (new Date(dayItem.timestamp).getTime()) === dayTimestamp)?.volDay

return {
totalVolume: `${totalVolume}`,
dailyVolume: dailyVolume ? `${dailyVolume}` : undefined,
timestamp: dayTimestamp,
};
}
};

const adapter = {
adapter: {
[mapChainId]: {
fetch: fetch(),
start: 1710086400,
customBackfill: customBackfill(mapChainId?.toString(), fetch)
}
}
};

export default adapter;
Loading