forked from DefiLlama/dimension-adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters