Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kibana fixes #1915

Merged
merged 9 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dexs/apeswap/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as sdk from "@defillama/sdk";
import { CHAIN } from "../../helpers/chains";
import { univ2Adapter } from "../../helpers/getUniSubgraphVolume";
import { univ2Adapter2 } from "../../helpers/getUniSubgraphVolume";

const adapters = univ2Adapter({
const adapters = univ2Adapter2({
[CHAIN.BSC]: sdk.graph.modifyEndpoint('GH4Zt29mCApHwMfavNFw5ZdQDH3owc2Wq8DdU4hGPXYe'),
[CHAIN.POLYGON]: sdk.graph.modifyEndpoint('EcLNjgAFADeXVopmhv3HY79fayzXRtK8R9imZNopRBpE'),
[CHAIN.ETHEREUM]: sdk.graph.modifyEndpoint('6J4fEY6pSRsqaqDbHn17HJY1viPzrGc1pjCqBKrrQXPC'),
Expand Down
106 changes: 22 additions & 84 deletions dexs/based-markets/index.ts
Original file line number Diff line number Diff line change
@@ -1,92 +1,30 @@
import * as sdk from "@defillama/sdk";
import request, { gql } from "graphql-request";
import { FetchResultVolume, SimpleAdapter } from "../../adapters/types";
import { SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import BigNumber from "bignumber.js";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";

const ONE_DAY_IN_SECONDS = 60 * 60 * 24

const endpoint = sdk.graph.modifyEndpoint('3E7EJF1zWHD3LHTKV5L6dspCno2ghxZ3WYe9MN7QVnEE')

const query = gql`
query stats($from: String!, $to: String!) {
dailyHistories(where: {timestamp_gte: $from, timestamp_lte: $to, accountSource: "0x1c03B6480a4efC2d4123ba90d7857f0e1878B780"}){
timestamp
platformFee
accountSource
tradeVolume
}
totalHistories(where: {accountSource: "0x1c03B6480a4efC2d4123ba90d7857f0e1878B780"}) {
timestamp
platformFee
accountSource
tradeVolume
}
}
`


interface IGraphResponse {
dailyHistories: Array<{
tiemstamp: string,
platformFee: string,
accountSource: string,
tradeVolume: string
}>
totalHistories: Array<{
tiemstamp: string,
platformFee: string,
accountSource: string,
tradeVolume: BigNumber
}>
}

const toString = (x: BigNumber) => {
if (x.isEqualTo(0)) return undefined
return x.toString()
}

const fetchVolume = async (timestamp: number): Promise<FetchResultVolume> => {
const response: IGraphResponse = await request(endpoint, query, {
from: String(timestamp - ONE_DAY_IN_SECONDS),
to: String(timestamp)
})


let dailyVolume = new BigNumber(0);
response.dailyHistories.forEach(data => {
dailyVolume = dailyVolume.plus(new BigNumber(data.tradeVolume))
});

let totalVolume = new BigNumber(0);
response.totalHistories.forEach(data => {
totalVolume = totalVolume.plus(new BigNumber(data.tradeVolume))
});

dailyVolume = dailyVolume.dividedBy(new BigNumber(1e18))
totalVolume = totalVolume.dividedBy(new BigNumber(1e18))

const _dailyVolume = toString(dailyVolume)
const _totalVolume = toString(totalVolume)

const dayTimestamp = getUniqStartOfTodayTimestamp(new Date((timestamp * 1000)))

return {
timestamp: dayTimestamp,
dailyVolume: _dailyVolume,
totalVolume: _totalVolume,
}

}
import { getGraphDimensions2 } from "../../helpers/getUniSubgraph";

const fetch = getGraphDimensions2({
graphUrls: {
[CHAIN.BASE]: sdk.graph.modifyEndpoint(
"3E7EJF1zWHD3LHTKV5L6dspCno2ghxZ3WYe9MN7QVnEE",
),
},
totalVolume: {
factory: "factories",
},
totalFees: {
factory: "factories",
},
});

const adapter: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.BASE]: {
fetch: fetchVolume,
start: 1704009000
}
}
}
fetch: fetch(CHAIN.BASE),
start: 1704009000,
},
},
};

export default adapter;
4 changes: 2 additions & 2 deletions dexs/camelot/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as sdk from "@defillama/sdk";
import { CHAIN } from "../../helpers/chains";
import { univ2Adapter } from "../../helpers/getUniSubgraphVolume";
import { univ2Adapter2 } from "../../helpers/getUniSubgraphVolume";

const adapters = univ2Adapter({
const adapters = univ2Adapter2({
[CHAIN.ARBITRUM]: sdk.graph.modifyEndpoint('8zagLSufxk5cVhzkzai3tyABwJh53zxn9tmUYJcJxijG')
}, {});

Expand Down
10 changes: 4 additions & 6 deletions dexs/clipper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@ import * as sdk from "@defillama/sdk";
import { Chain } from "@defillama/sdk/build/general";
import { SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
const {
getChainVolume,
} = require("../../helpers/getUniSubgraphVolume");
import { getChainVolume2 } from "../../helpers/getUniSubgraphVolume";

const endpoints = {
[CHAIN.ETHEREUM]: sdk.graph.modifyEndpoint('2BhN8mygHMmRkceMmod7CEEsGkcxh91ExRbEfRVkpVGM'),
[CHAIN.OPTIMISM]: sdk.graph.modifyEndpoint('Cu6atAfi6uR9mLMEBBjkhKSUUXHCobbB83ctdooexQ9f'),
[CHAIN.POLYGON]: sdk.graph.modifyEndpoint('Brmf2gRdpLFsEF6YjSAMVrXqSfbhsaaWaWzdCYjE7iYY'),
[CHAIN.MOONBEAN]: sdk.graph.modifyEndpoint('8zRk4WV9vUU79is2tYGWq9GKh97f93LsZ8V9wy1jSMvA'),
// [CHAIN.MOONBEAN]: sdk.graph.modifyEndpoint('8zRk4WV9vUU79is2tYGWq9GKh97f93LsZ8V9wy1jSMvA'),
[CHAIN.ARBITRUM]: sdk.graph.modifyEndpoint('ATBQPRjT28GEK6UaBAzXy64x9kFkNk1r64CdgmDJ587W'),
};


const VOLUME_FIELD = "volumeUSD";
const graphs = getChainVolume({
const graphs = getChainVolume2({
graphUrls: endpoints,
totalVolume: {
factory: "pools",
field: VOLUME_FIELD,
},
hasDailyVolume: false,
});


Expand Down
4 changes: 2 additions & 2 deletions dexs/dragonswap-sei/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CHAIN } from "../../helpers/chains";
import { univ2Adapter } from "../../helpers/getUniSubgraphVolume";
import { univ2Adapter2 } from "../../helpers/getUniSubgraphVolume";

const adapters = univ2Adapter({
const adapters = univ2Adapter2({
[CHAIN.SEI]: "https://api.goldsky.com/api/public/project_clu1fg6ajhsho01x7ajld3f5a/subgraphs/dragonswap-prod/1.0.0/gn"
}, {});

Expand Down
7 changes: 2 additions & 5 deletions dexs/hercules-v3/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// https://metisapi.0xgraph.xyz/subgraphs/name/cryptoalgebra/analytics
import { CHAIN } from "../../helpers/chains";
import { univ2Adapter } from "../../helpers/getUniSubgraphVolume";
import { univ2Adapter2 } from "../../helpers/getUniSubgraphVolume";

const adapters = univ2Adapter({
const adapters = univ2Adapter2({
[CHAIN.METIS]: "https://metisapi.0xgraph.xyz/subgraphs/name/cryptoalgebra/analytics"
}, {
factoriesName: "factories",
dayData: "algebraDayData",
dailyVolume: "volumeUSD",
totalVolume: "totalVolumeUSD",
});

Expand Down
16 changes: 10 additions & 6 deletions dexs/pangolin/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import * as sdk from "@defillama/sdk";
import { univ2Adapter } from "../../helpers/getUniSubgraphVolume";
import { univ2Adapter2 } from "../../helpers/getUniSubgraphVolume";

export default univ2Adapter({
"avax": sdk.graph.modifyEndpoint('CPXTDcwh6tVP88QvFWW7pdvZJsCN4hSnfMmYeF1sxCLq')
}, {
export default univ2Adapter2(
{
avax: sdk.graph.modifyEndpoint(
"CPXTDcwh6tVP88QvFWW7pdvZJsCN4hSnfMmYeF1sxCLq",
),
},
{
factoriesName: "pangolinFactories",
dayData: "pangolinDayData",
});
},
);
5 changes: 2 additions & 3 deletions dexs/pulsex-v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { CHAIN } from "../../helpers/chains";
import { univ2Adapter } from "../../helpers/getUniSubgraphVolume";
import { univ2Adapter2 } from "../../helpers/getUniSubgraphVolume";

const adapters = univ2Adapter({
const adapters = univ2Adapter2({
[CHAIN.PULSECHAIN]: "https://graph.pulsechain.com/subgraphs/name/pulsechain/pulsexv2"
}, {
factoriesName: "pulseXFactories",
dayData: "pulsexDayData",
});

adapters.adapter.pulse.start = 1685577600;
Expand Down
14 changes: 6 additions & 8 deletions dexs/syncswap/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { univ2Adapter } from "../../helpers/getUniSubgraphVolume";
import { univ2Adapter2 } from "../../helpers/getUniSubgraphVolume";
import { CHAIN } from "../../helpers/chains";

const endpoints = {
[CHAIN.ERA]: "https://api.studio.thegraph.com/query/30365/syncswap-graph/1.4.0",
[CHAIN.ERA]:
"https://api.studio.thegraph.com/query/30365/syncswap-graph/1.4.0",
};

const adapter = univ2Adapter(endpoints, {
const adapter = univ2Adapter2(endpoints, {
factoriesName: "syncSwapFactories",
dayData: "dayData",
dailyVolume: "dailyVolumeUSD",
totalVolume: "totalVolumeUSD",
dailyVolumeTimestampField: "date",
});

adapter.adapter.era.start = 1679529600
adapter.adapter.era.start = 1679529600;

export default adapter
export default adapter;
7 changes: 2 additions & 5 deletions dexs/thena/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import * as sdk from "@defillama/sdk";
import { CHAIN } from "../../helpers/chains";
import { univ2Adapter } from "../../helpers/getUniSubgraphVolume";
import { univ2Adapter2 } from "../../helpers/getUniSubgraphVolume";

const adapters = univ2Adapter({
const adapters = univ2Adapter2({
[CHAIN.BSC]: sdk.graph.modifyEndpoint('FKEt2N5VmSdEYcz7fYLPvvnyEUkReQ7rvmXzs6tiKCz1')
}, {
factoriesName: "factories",
totalVolume: "totalVolumeUSD",
dayData: "dayData",
dailyVolume: "dailyVolumeUSD",
dailyVolumeTimestampField: "date"
});

adapters.adapter.bsc.start = 1672790400;
Expand Down
5 changes: 2 additions & 3 deletions dexs/vvs-finance/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { univ2Adapter } from "../../helpers/getUniSubgraphVolume";
import { univ2Adapter2 } from "../../helpers/getUniSubgraphVolume";

const adapter = univ2Adapter({
const adapter = univ2Adapter2({
"cronos": "https://graph.cronoslabs.com/subgraphs/name/vvs/exchange"
},{
factoriesName: "vvsFactories",
dayData: "vvsDayData",
});

adapter.adapter.cronos.start = 1632035122; // 1 a year ago
Expand Down
8 changes: 2 additions & 6 deletions dexs/zebra-v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@

// https://api.studio.thegraph.com/query/55584/v3_scroll/version/latest
import { univ2Adapter } from "../../helpers/getUniSubgraphVolume";
import { univ2Adapter2 } from "../../helpers/getUniSubgraphVolume";
import { CHAIN } from "../../helpers/chains";

const endpoints = {
[CHAIN.SCROLL]: "https://api.studio.thegraph.com/query/55584/v3_scroll/version/latest",
};

const adapter = univ2Adapter(endpoints, {
const adapter = univ2Adapter2(endpoints, {
factoriesName: "factories",
dayData: "uniswapDayData",
dailyVolume: "volumeUSD",
totalVolume: "totalVolumeUSD",
dailyVolumeTimestampField: "date",
});

adapter.adapter.scroll.start = 1700697600
Expand Down
2 changes: 1 addition & 1 deletion helpers/getUniSubgraphVolume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function getChainVolume2({
}
`;

const graphQueryTotalVolume = gql`${hasTotalVolume ? `query get_total_volume($block: Int) { ${totalVolumeQuery} }` : ""}`
const graphQueryTotalVolume = gql`query get_total_volume($block: Int) { ${totalVolumeQuery} }`

return (chain: Chain) => {
return async (options: FetchOptions) => {
Expand Down
Loading