Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowBirdy authored Nov 10, 2024
2 parents d99303d + 55983d8 commit 9d32cfc
Show file tree
Hide file tree
Showing 382 changed files with 1,590 additions and 1,209 deletions.
2 changes: 1 addition & 1 deletion adapters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export type IStartTimestamp = () => Promise<number>

export type BaseAdapter = {
[chain: string]: {
start?: IStartTimestamp | number
start?: IStartTimestamp | number | string; // date can be in "YYYY-MM-DD" format
fetch: Fetch | FetchV2;
runAtCurrTime?: boolean;
customBackfill?: Fetch | FetchV2;
Expand Down
39 changes: 22 additions & 17 deletions adapters/utils/runAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,30 +153,35 @@ export default async function runAdapter(volumeAdapter: BaseAdapter, cleanCurren

async function setChainValidStart(chain: string) {
const cleanPreviousDayTimestamp = cleanCurrentDayTimestamp - ONE_DAY_IN_SECONDS
const _start = volumeAdapter[chain]?.start
if (_start === undefined) return;
let _start = volumeAdapter[chain]?.start ?? 0
if (typeof _start === 'string') _start = new Date(_start).getTime() / 1000
// if (_start === undefined) return;

if (typeof _start === 'number') {
validStart[chain] = {
canRun: _start <= cleanPreviousDayTimestamp,
startTimestamp: _start
}
} else if (_start) {
const defaultStart = Math.trunc(Date.now() / 1000)
if (closeToCurrentTime) {// intentionally set to true to allow for backfilling
validStart[chain] = {
canRun: true,
startTimestamp: defaultStart
}
return;
}
const start = await (_start as any)().catch(() => {
console.error(`Failed to get start time for ${id} ${version} ${chain}`)
return defaultStart
})
return;
}

const defaultStart = Math.trunc(Date.now() / 1000)
if (closeToCurrentTime) {// intentionally set to true to allow for backfilling
validStart[chain] = {
canRun: typeof start === 'number' && start <= cleanPreviousDayTimestamp,
startTimestamp: start
canRun: true,
startTimestamp: defaultStart
}
return;
}

// if _start is an async function that returns timestamp
const start = await (_start as any)().catch(() => {
console.error(`Failed to get start time for ${id} ${version} ${chain}`)
return defaultStart
})
validStart[chain] = {
canRun: typeof start === 'number' && start <= cleanPreviousDayTimestamp,
startTimestamp: start
}
}
}
3 changes: 1 addition & 2 deletions aggregators/deflex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ const adapter: SimpleAdapter = {
fetch,
runAtCurrTime: true,
customBackfill: undefined,
start: 0,
},
},
}
};

Expand Down
41 changes: 41 additions & 0 deletions aggregators/navi/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { CHAIN } from "../../helpers/chains";
import { FetchOptions } from "../../adapters/types";
import axios from "axios";

const sentioApiKey = '3taTsrTS3cZq4tcKkKVSajWSJxkjZmcet'; //Read Only

const fetchDailyVolume = async ({ fromTimestamp, toTimestamp, startOfDay }: FetchOptions) => {
const url = 'https://app.sentio.xyz/api/v1/analytics/navi/dex-aggregator/sql/execute';
const res = await axios(url, {
method: 'POST',
headers: {
'api-key': sentioApiKey,
'Content-Type': 'application/json'
},
data: JSON.stringify({
sqlQuery: {
sql: `SELECT SUM(GREATEST(amount_in_usd, amount_out_usd)) AS usdValue
FROM \'swapEvent\'
WHERE timestamp >= ${fromTimestamp} AND timestamp <= ${toTimestamp};`
},
version: 15
})
}).then(response => response.data);

return {
dailyVolume: res.result.rows[0].usdValue,
}
};

//NAVI Aggregator Volume
const navi_aggregator: any = {
version: 2,
adapter: {
[CHAIN.SUI]: {
fetch: fetchDailyVolume,
start: 1728111600,
},
},
};

export default navi_aggregator;
4 changes: 2 additions & 2 deletions aggregators/rainbow-swap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {Fetch, SimpleAdapter} from "../../adapters/types";
import {CHAIN} from "../../helpers/chains";
import fetchURL from "../../utils/fetchURL";

const URL = 'https://api.blackbot.technology';
const endpoint = '/rainbow/analytics/volumes';
const URL = 'https://api.rainbow.ag';
const endpoint = '/analytics/volumes';
const start = 1720645200;// 11.07.2024

interface IAPIResponse {
Expand Down
101 changes: 30 additions & 71 deletions aggregators/zrx/index.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,48 @@
import { GraphQLClient, gql } from "graphql-request";

import { CHAIN } from "../../helpers/chains";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";
import { FetchOptions } from "../../adapters/types";
import { getEnv } from "../../helpers/env";
import axios from "axios";

type TChain = {
[key: string]: string;
[key: string]: number;
};
const CHAINS: TChain = {
[CHAIN.ARBITRUM]: "Arbitrum",
[CHAIN.AVAX]: "Avalanche",
[CHAIN.BASE]: "Base",
[CHAIN.BSC]: "BSC",
[CHAIN.CELO]: "Celo",
[CHAIN.ETHEREUM]: "Ethereum",
[CHAIN.FANTOM]: "Fantom",
[CHAIN.OPTIMISM]: "Optimism",
[CHAIN.POLYGON]: "Polygon",
};

const graphQLClient = new GraphQLClient("https://api.0x.org/data/v0");
const getGQLClient = () => {
graphQLClient.setHeader("0x-api-key", getEnv("AGGREGATOR_0X_API_KEY"));

return graphQLClient;
[CHAIN.ARBITRUM]: 42161,
[CHAIN.AVAX]: 43114,
[CHAIN.BASE]: 8453,
[CHAIN.BSC]: 56,
[CHAIN.ETHEREUM]: 1,
[CHAIN.OPTIMISM]: 10,
[CHAIN.POLYGON]: 137,
[CHAIN.BLAST]: 81457,
[CHAIN.LINEA]: 59144,
[CHAIN.SCROLL]: 534352,
[CHAIN.MANTLE]: 5000,
[CHAIN.MODE]: 34443,
};

const getVolumeByChain = async (chain: string) => {
const client = getGQLClient();
const req = gql`
query Query_root {
aggTransactionsDailyRouter(
order_by: [{ timestamp: desc, chainName: null }]
where: { chainName: { _eq: ${chain} } }
) {
chainName
timestamp
transactions
volumeUSD
}
const fetch = async (_a, _b, options: FetchOptions) => {
const data = await axios.get(`https://api.0x.org/stats/volume/daily?timestamp=${options.startOfDay}&chainId=${CHAINS[options.chain]}`, {
headers: {
"0x-api-key": getEnv("AGGREGATOR_0X_API_KEY")
}
`;

const data = (await client.request(req))["aggTransactionsDailyRouter"];
return data;
};

const fetch = async (options: FetchOptions) => {
const unixTimestamp = getUniqStartOfTodayTimestamp(
new Date(options.endTimestamp * 1000)
);
try {
const data = await getVolumeByChain(options.chain);
const strDate = new Date(unixTimestamp * 1000).toISOString().split("T")[0];
const dayData = data.find(
({ timestamp }: { timestamp: string }) =>
timestamp.split("T")[0] === strDate
);
return {
dailyVolume: dayData?.volumeUSD,
timestamp: unixTimestamp,
};
} catch (e) {
console.error(e);
return {
dailyVolume: "0",
timestamp: unixTimestamp,
};
})
return {
dailyVolume: data.data.data.volume
}
};

const adapter: any = {
version: 1,
adapter: {
...Object.values(CHAINS).reduce((acc, chain) => {
return {
...acc,
[chain]: {
fetch: fetch,
start: 1652745600,
},
};
}, {}),
},
adapter: Object.keys(CHAINS).reduce((acc, chain) => {
return {
...acc,
[chain]: {
fetch: fetch,
start: 1652745600,
},
};
}, {}),
};

export default adapter;
3 changes: 1 addition & 2 deletions dexs/4swap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ const adapter: SimpleAdapter = {
fetch,
runAtCurrTime: true,
customBackfill: undefined,
start: 0,
},
},
}
};

Expand Down
3 changes: 1 addition & 2 deletions dexs/algofi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ const adapter: SimpleAdapter = {
fetch,
runAtCurrTime: true,
customBackfill: undefined,
start: 0,
},
},
}
};

Expand Down
17 changes: 1 addition & 16 deletions dexs/apex-omni/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,7 @@ interface IOpenInterest {
}

const getVolume = async (timestamp: number) => {
const symbol = [
'BTCUSDT', 'ETHUSDT', 'SOLUSDT',
'TONUSDT', 'NEARUSDT', 'XRPUSDT',
'ADAUSDT', 'SUIUSDT', 'AVAXUSDT',
'BCHUSDT', 'LTCUSDT', 'MATICUSDT',
'ARBUSDT', 'OPUSDT', 'STXUSDT',
'DOGEUSDT', '1000SHIBUSDT', '1000PEPEUSDT',
'1000BONKUSDT', 'WIFUSDT', 'ORDIUSDT',
'PEOPLEUSDT', 'WLDUSDT', 'RNDRUSDT',
'ONDOUSDT', 'LINKUSDT', 'ENSUSDT',
'UNIUSDT', 'ENAUSDT', 'PENDLEUSDT',
'LDOUSDT', 'JUPUSDT', 'RONUSDT',
'FILUSDT', 'ARUSDT', 'ZKUSDT',
'IOUSDT', 'NOTUSDT', 'ZROUSDT',
'BLASTUSDT'
]
const symbol = (await getSumbols());

const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const historical: any[] = (await Promise.all(symbol.map((coins: string) => httpGet(historicalVolumeEndpoint(coins, dayTimestamp + 60 * 60 * 24), { timeout: 10000 }))))
Expand Down
15 changes: 5 additions & 10 deletions dexs/astroport-v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,27 @@ const adapter: SimpleAdapter = {
fetch: fetch("phoenix-1"),
runAtCurrTime: true,
customBackfill: undefined,
start: 0,
},
},
[CHAIN.INJECTIVE]: {
fetch: fetch("injective-1"),
runAtCurrTime: true,
customBackfill: undefined,
start: 0,
},
},
neutron: {
fetch: fetch("neutron-1"),
runAtCurrTime: true,
customBackfill: undefined,
start: 0,
},
},
[CHAIN.SEI]: {
fetch: fetch("pacific-1"),
runAtCurrTime: true,
customBackfill: undefined,
start: 0,
},
},
[CHAIN.OSMOSIS]: {
fetch: fetch("osmosis-1"),
runAtCurrTime: true,
customBackfill: undefined,
start: 0,
}
}
},
};

Expand Down
3 changes: 1 addition & 2 deletions dexs/astroport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ const adapter: SimpleAdapter = {
},
runAtCurrTime: true,
customBackfill: undefined,
start: 0,
},
},
},
};

Expand Down
3 changes: 1 addition & 2 deletions dexs/bancor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ const adapter: BreakdownAdapter = {
[CHAIN.ETHEREUM]: {
fetch: fetchV3,
runAtCurrTime: true,
start: 0,
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dexs/bluemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const adapter: SimpleAdapter = {
adapter: {
[CHAIN.APTOS]: {
fetch,
start: 1666224000,
start: '2022-10-20',
},
},
version: 1
Expand Down
14 changes: 13 additions & 1 deletion dexs/camelot-v3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ import { CHAIN } from "../../helpers/chains";
import { univ2Adapter2 } from "../../helpers/getUniSubgraphVolume";

const adapters = univ2Adapter2({
[CHAIN.ARBITRUM]: sdk.graph.modifyEndpoint('7mPnp1UqmefcCycB8umy4uUkTkFxMoHn1Y7ncBUscePp')
[CHAIN.ARBITRUM]: sdk.graph.modifyEndpoint('7mPnp1UqmefcCycB8umy4uUkTkFxMoHn1Y7ncBUscePp'),
[CHAIN.APECHAIN]: `https://subgraph.satsuma-prod.com/${process.env.CAMELOT_API_KEY}/camelot/camelot-ammv3-apechain/api`,
[CHAIN.GRAVITY]: `https://subgraph.satsuma-prod.com/${process.env.CAMELOT_API_KEY}/camelot/camelot-ammv3-gravity/api`,
[CHAIN.RARI]: `https://subgraph.satsuma-prod.com/${process.env.CAMELOT_API_KEY}/camelot/camelot-ammv3-rari/api`,
[CHAIN.REYA]: `https://subgraph.satsuma-prod.com/${process.env.CAMELOT_API_KEY}/camelot/camelot-ammv3-reya/api`,
[CHAIN.XDAI]: `https://subgraph.satsuma-prod.com/${process.env.CAMELOT_API_KEY}/camelot/camelot-ammv3-xai/api`,
[CHAIN.SANKO]: `https://subgraph.satsuma-prod.com/${process.env.CAMELOT_API_KEY}/camelot/camelot-ammv3-sanko/api`,
}, {
factoriesName: "factories",
totalVolume: "totalVolumeUSD",
});

adapters.adapter.arbitrum.start = 1680220800;
adapters.adapter.apechain.start = 1680220800;
adapters.adapter.gravity.start = 1680220800;
adapters.adapter.rari.start = 1680220800;
adapters.adapter.reya.start = 1680220800;
adapters.adapter.xdai.start = 1680220800;
adapters.adapter.sanko.start = 1680220800;
export default adapters;
8 changes: 7 additions & 1 deletion dexs/camelot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { CHAIN } from "../../helpers/chains";
import { univ2Adapter2 } from "../../helpers/getUniSubgraphVolume";

const adapters = univ2Adapter2({
[CHAIN.ARBITRUM]: sdk.graph.modifyEndpoint('8zagLSufxk5cVhzkzai3tyABwJh53zxn9tmUYJcJxijG')
[CHAIN.ARBITRUM]: sdk.graph.modifyEndpoint('8zagLSufxk5cVhzkzai3tyABwJh53zxn9tmUYJcJxijG'),
[CHAIN.APECHAIN]: `https://subgraph.satsuma-prod.com/${process.env.CAMELOT_API_KEY}/camelot/camelot-ammv2-apechain/api`,
[CHAIN.GRAVITY]: `https://subgraph.satsuma-prod.com/${process.env.CAMELOT_API_KEY}/camelot/camelot-ammv2-gravity/api`,
[CHAIN.RARI]: `https://subgraph.satsuma-prod.com/${process.env.CAMELOT_API_KEY}/camelot/camelot-ammv2-rari/api`,
[CHAIN.REYA]: `https://subgraph.satsuma-prod.com/${process.env.CAMELOT_API_KEY}/camelot/camelot-ammv2-reya/api`,
[CHAIN.XDAI]: `https://subgraph.satsuma-prod.com/${process.env.CAMELOT_API_KEY}/camelot/camelot-ammv2-xai/api`,
[CHAIN.SANKO]: `https://subgraph.satsuma-prod.com/${process.env.CAMELOT_API_KEY}/camelot/camelot-ammv2-sanko/api`,
}, {});

adapters.adapter.arbitrum.start = 1668124800;
Expand Down
Loading

0 comments on commit 9d32cfc

Please sign in to comment.