Skip to content

Commit

Permalink
feet: add zkera-finance adapter (#2064)
Browse files Browse the repository at this point in the history
* feet: add zkera-finance adapter

* upd: add liquidation to volumes
  • Loading branch information
zkeraFi authored Nov 8, 2024
1 parent 848b23d commit ab01e59
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
14 changes: 14 additions & 0 deletions dexs/zkera-finance/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { fetchVolume } from "./zkera";

const adapter: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.TELOS]: {
fetch: fetchVolume,
start: 1627690586,
},
},
};
export default adapter;
46 changes: 46 additions & 0 deletions dexs/zkera-finance/zkera.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { request, gql } from "graphql-request";
import { FetchOptions } from "../../adapters/types";
import BigNumber from "bignumber.js";

const graphUrl =
"https://api.goldsky.com/api/public/project_clzelu5d634f501x8ai8111wj/subgraphs/zlp-pool/latest/gn";
const getData = async (timestamp: number) => {
const query = gql`
{
volumeStats(first: 1, where: { period: daily, timestamp: ${timestamp} }) {
id
burn
margin
liquidation
mint
period
timestamp
}
}
`;
const response = await request(graphUrl, query);
let dailyVolume = new BigNumber(0);
if (response.volumeStats) {
const data = response.volumeStats[0];
dailyVolume = dailyVolume
.plus(new BigNumber(data.mint))
.plus(new BigNumber(data.liquidation))
.plus(new BigNumber(data.burn))
.plus(new BigNumber(data.margin))
.dividedBy(new BigNumber(1e30));
}
const _dailyVolume = dailyVolume.toString();

return {
dailyVolume: _dailyVolume,
timestamp: timestamp,
};
};

export const fetchVolume = async (options: FetchOptions) => {
const data = await getData(options.startOfDay);
return {
dailyVolume: data.dailyVolume,
timestamp: data.timestamp,
};
};

0 comments on commit ab01e59

Please sign in to comment.