Skip to content

Commit

Permalink
Merge pull request #1767 from DefiLlama/jupiter-perpetual-update
Browse files Browse the repository at this point in the history
fix jupiter-perpetual
  • Loading branch information
dtmkeng committed Aug 13, 2024
2 parents 4a28003 + 035589f commit 098d0f3
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions dexs/jupiter-perpetual/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
import { FetchResult } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";
import { queryDune } from "../../helpers/dune";
import { httpGet } from "../../utils/fetchURL";

const list_of_mints: string[] = [
"So11111111111111111111111111111111111111112",
"3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh",
"7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs",
]

const fetch = async (timestamp: number): Promise<FetchResult> => {
const unixTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
// 3385640 old query id
const data = await queryDune("3391484", { endTime: unixTimestamp + 86400 });
const header_user = {
"accept": "*/*",
"accept-language": "en-US,en;q=0.9",
"content-type": "application/json",
"sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"90\", \"Google Chrome\";v=\"90\"",
"sec-ch-ua-mobile": "?0",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site",
"sec-gpc": "1",
"referrer": "https://www.jup.ag/",
"referrerPolicy": "strict-origin-when-cross-origin",
"mode": "cors",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36",
}
const url = (token: string) => `https://perp-api.jup.ag/trpc/tradeVolume?batch=1&input={"0":{"json":{"mint":"${token}"}}}`
const fetches = (await Promise.all(list_of_mints.map(token => httpGet(url(token), { headers: header_user })))).flat();
const dailyVolume = fetches.reduce((acc, { result }) => acc + result.data.json.volume, 0);
return {
dailyVolume: data[0].volume,
timestamp: unixTimestamp,
dailyVolume: dailyVolume,
timestamp: timestamp,
};
};

const adapter = {
version: 2,
breakdown: {
derivatives: {
[CHAIN.SOLANA]: {
Expand All @@ -22,8 +43,6 @@ const adapter = {
start: 1705968000,
},
},
},
isExpensiveAdapter: true,
}
};

export default adapter;

0 comments on commit 098d0f3

Please sign in to comment.