Skip to content

Commit

Permalink
quickswap
Browse files Browse the repository at this point in the history
  • Loading branch information
waynebruce0x committed Sep 12, 2024
1 parent e6e8feb commit e119cd2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 35 deletions.
75 changes: 45 additions & 30 deletions dexs/quickswap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ import * as sdk from "@defillama/sdk";
import { BreakdownAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getGraphDimensions } from "../../helpers/getUniSubgraph";
import { DEFAULT_DAILY_VOLUME_FACTORY, DEFAULT_DAILY_VOLUME_FIELD, DEFAULT_TOTAL_VOLUME_FACTORY, DEFAULT_TOTAL_VOLUME_FIELD, getChainVolume } from "../../helpers/getUniSubgraphVolume";
import fetchURL from "../../utils/fetchURL"
import {
DEFAULT_DAILY_VOLUME_FACTORY,
DEFAULT_DAILY_VOLUME_FIELD,
DEFAULT_TOTAL_VOLUME_FACTORY,
DEFAULT_TOTAL_VOLUME_FIELD,
getChainVolume,
} from "../../helpers/getUniSubgraphVolume";
import fetchURL from "../../utils/fetchURL";

const endpoints = {
[CHAIN.POLYGON]: sdk.graph.modifyEndpoint('FUWdkXWpi8JyhAnhKL5pZcVshpxuaUQG8JHMDqNCxjPd'),
[CHAIN.POLYGON]: sdk.graph.modifyEndpoint(
"FUWdkXWpi8JyhAnhKL5pZcVshpxuaUQG8JHMDqNCxjPd",
),
};

const graphs = getChainVolume({
Expand All @@ -18,20 +26,27 @@ const graphs = getChainVolume({
dailyVolume: {
factory: DEFAULT_DAILY_VOLUME_FACTORY,
field: DEFAULT_DAILY_VOLUME_FIELD,
dateField: "date"
dateField: "date",
},
hasDailyVolume: true,
});

const endpointsAlgebraV3 = {
[CHAIN.POLYGON]: sdk.graph.modifyEndpoint('CCFSaj7uS128wazXMdxdnbGA3YQnND9yBdHjPtvH7Bc7'),
[CHAIN.POLYGON]: sdk.graph.modifyEndpoint(
"CCFSaj7uS128wazXMdxdnbGA3YQnND9yBdHjPtvH7Bc7",
),
// [CHAIN.DOGECHAIN]: "https://graph-node.dogechain.dog/subgraphs/name/quickswap/dogechain-info",
[CHAIN.POLYGON_ZKEVM]:"https://api.studio.thegraph.com/query/44554/quickswap-v3-02/0.0.7",
[CHAIN.MANTA]:"https://api.goldsky.com/api/public/project_clo2p14by0j082owzfjn47bag/subgraphs/quickswap/prod/gn"
[CHAIN.POLYGON_ZKEVM]:
"https://api.studio.thegraph.com/query/44554/quickswap-v3-02/0.0.7",
[CHAIN.MANTA]:
"https://api.goldsky.com/api/public/project_clo2p14by0j082owzfjn47bag/subgraphs/quickswap/prod/gn",
};

const endpointsUniV3 = {
[CHAIN.MANTA]:"https://api.goldsky.com/api/public/project_clo2p14by0j082owzfjn47bag/subgraphs/quickswap/prod/gn",
[CHAIN.ASTAR_ZKEVM]:"https://api.studio.thegraph.com/query/44554/astar-quickswap/version/latest"
[CHAIN.MANTA]:
"https://api.goldsky.com/api/public/project_clo2p14by0j082owzfjn47bag/subgraphs/quickswap/prod/gn",
[CHAIN.ASTAR_ZKEVM]:
"https://api.studio.thegraph.com/query/44554/astar-quickswap/version/latest",
};

const graphsAlgebraV3 = getChainVolume({
Expand All @@ -43,7 +58,7 @@ const graphsAlgebraV3 = getChainVolume({
dailyVolume: {
factory: "algebraDayData",
field: "volumeUSD",
dateField: "date"
dateField: "date",
},
});

Expand All @@ -67,55 +82,55 @@ const v3GraphsUni = getGraphDimensions({
},
});


const fetchLiquidityHub = async (timestamp: number) => {
let dailyResult = (await fetchURL('https://hub.orbs.network/analytics-daily/v1'));

let rows = dailyResult.result.rows;
let lastDay = rows[rows.length - 1];
let dailyVolume = lastDay.daily_total_calculated_value;
let totalVolume = (await fetchURL(`https://hub.orbs.network/analytics/v1`)).result.rows[0].total_calculated_value;

return {
dailyVolume: `${dailyVolume}`,
totalVolume: `${totalVolume}`,
timestamp: timestamp,
};
let dailyResult = await fetchURL(
"https://hub.orbs.network/analytics-daily/v1",
);

}
let rows = dailyResult.result.rows;
let lastDay = rows[rows.length - 1];
let dailyVolume = lastDay.daily_total_calculated_value;
let totalVolume = (await fetchURL(`https://hub.orbs.network/analytics/v1`))
.result.rows[0].total_calculated_value;

return {
dailyVolume: `${dailyVolume}`,
totalVolume: `${totalVolume}`,
timestamp: timestamp,
};
};

const adapter: BreakdownAdapter = {
version: 1,
breakdown: {
v2: {
[CHAIN.POLYGON]: {
fetch: graphs(CHAIN.POLYGON),
start: 1602118043
start: 1602118043,
},
},
v3: {
[CHAIN.POLYGON]: {
fetch: graphsAlgebraV3(CHAIN.POLYGON),
start: 1662425243
start: 1662425243,
},
// [CHAIN.DOGECHAIN]: {
// fetch: graphsV3(CHAIN.DOGECHAIN),
// start: 1660694400
// },
[CHAIN.POLYGON_ZKEVM]: {
fetch: graphsAlgebraV3(CHAIN.POLYGON_ZKEVM),
start: 1679875200
start: 1679875200,
},
[CHAIN.MANTA]: {
fetch: v3GraphsUni(CHAIN.MANTA),
start: 1697690974
}
start: 1697690974,
},
},
liquidityHub: {
[CHAIN.POLYGON]: {
fetch: fetchLiquidityHub,
start: 1695042000
start: 1695042000,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion helpers/getUniSubgraph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function getGraphDimensions({
}
`
: undefined;
return async (options: FetchOptions) => {
return async (_a: any, _b: any, options: FetchOptions) => {
const { endTimestamp, getEndBlock } = options;
// ts-node --transpile-only cli/testAdapter.ts protocols uniswap
const customBlockFunc = getCustomBlock ? getCustomBlock : getEndBlock;
Expand Down
8 changes: 4 additions & 4 deletions helpers/getUniSubgraphVolume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function getChainVolume({
const graphQueryDailyVolume = gql`${hasDailyVolume ? `query get_daily_volume($id: Int) { ${dailyVolumeQuery} }` : ""}`;

return (chain: Chain) => {
return async (options: FetchOptions) => {
return async (_a: any, _b: any, options: FetchOptions) => {
const { endTimestamp, getEndBlock, getFromBlock, getToBlock } = options;
const customBlockFunc = getCustomBlock ? getCustomBlock : getEndBlock;
const block = (await customBlockFunc(endTimestamp).catch((e: any) =>
Expand Down Expand Up @@ -259,12 +259,12 @@ function getChainVolumeWithGasToken({
}: IGetChainVolumeParams & {priceToken:string}) {
const basic = getChainVolume({graphUrls, totalVolume, dailyVolume, customDailyVolume, hasDailyVolume, hasTotalVolume, getCustomBlock})
return (chain: Chain) => {
return async (options: FetchOptions) => {
return async (_a: any, _b: any, options: FetchOptions) => {
const {
block,
totalVolume,
dailyVolume,
} = await basic(chain)(options);
} = await basic(chain)(_a, _b, options);

const timestamp = options.endTimestamp
const balances = new Balances({ chain, timestamp })
Expand Down Expand Up @@ -373,7 +373,7 @@ function univ2Adapter2(endpoints: {
dailyVolumeTimestampField = DEFAULT_DATE_FIELD,
gasToken = null as string|null
}) {
const graphs = (gasToken === null ? getChainVolume2 : getChainVolumeWithGasToken2 as typeof getChainVolume)({
const graphs = (gasToken === null ? getChainVolume2 : getChainVolumeWithGasToken2 as typeof getChainVolume2)({
graphUrls: endpoints,
totalVolume: {
factory: factoriesName,
Expand Down

0 comments on commit e119cd2

Please sign in to comment.