Skip to content

Commit

Permalink
add merlinSwap adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
LpcAries committed Apr 30, 2024
1 parent c51f333 commit 5fe53ee
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
73 changes: 73 additions & 0 deletions dexs/merlinswap/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import fetchURL from "../../utils/fetchURL"
import { Chain } from "@defillama/sdk/build/general";
import { FetchOptions, FetchResultVolume, SimpleAdapter } from "../../adapters/types";
import customBackfill from "../../helpers/customBackfill";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";


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

interface IVolumeall {
volDay: number;
chainId: number;
timestamp: number;
}
type TChains = {
[k: Chain | string]: number;
};
type TAdapter = {
[key:string]: any;
};

const chains: TChains = {
[CHAIN.MERLIN]: 4200,
};

const fetch = async (options: FetchOptions): Promise<FetchResultVolume> => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(options.endTimestamp * 1000))
let isSuccess = true;
let page = 1;
const historical: IVolumeall[] = [];
while (isSuccess) {
const response = (await fetchURL(historicalVolumeEndpoint(chains[options.chain], page)));
if (response.is_success){
Array.prototype.push.apply(historical, response.data);
page += 1;
} else {
isSuccess = false;
};
};
const historicalVolume = historical.filter(e => e.chainId === chains[options.chain]);
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 adapters: TAdapter = {};
for (const chain in chains) {
let startTime = 1706946000;
if (chains.hasOwnProperty(chain)) {
adapters[chain] = {
fetch: fetch,
start: startTime,
customBackfill: customBackfill(chain, () => fetch)
};
};
};

const adapter: SimpleAdapter = {
adapter: adapters,
version: 2,
};

export default adapter;
3 changes: 2 additions & 1 deletion helpers/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ export enum CHAIN {
SVM = "svm",
ASTRZK = "astrzk",
LYRA = "lyra",
XLAYER = "xlayer"
XLAYER = "xlayer",
MERLIN = "merlin"
}

// Don´t use
Expand Down

0 comments on commit 5fe53ee

Please sign in to comment.