Skip to content

Commit

Permalink
Merge branch 'master' into getPrices
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmkeng authored Feb 10, 2024
2 parents e2f27b0 + 8ffe355 commit dc9ac09
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 36 deletions.
2 changes: 1 addition & 1 deletion dexs/chainge-finance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const fetch = async (timestamp: number) => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000))
const response: IAPIResponse = (await fetchURL(URL)).data.Total;
return {
dailyVolume: `${response.totalVolume}`,
dailyVolume: `${response?.totalVolume}` || undefined,
timestamp: dayTimestamp,
};
};
Expand Down
24 changes: 12 additions & 12 deletions dexs/elk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ const adapter = univ2Adapter({
// [CHAIN.HECO]: "https://api.thegraph.com/subgraphs/name/elkfinance/elkdex-heco"
[CHAIN.XDAI]: "https://api.thegraph.com/subgraphs/name/elkfinance/elkdex-xdai",
// [CHAIN.MOONRIVER]: "https://moonriver-graph.elk.finance/subgraphs/name/elkfinance/elkdex-moonriver",
[CHAIN.ELASTOS]: "https://elastos-graph.elk.finance/subgraphs/name/elkfinance/elkdex-elastos",
[CHAIN.OKEXCHAIN]: "https://okex-graph.elk.finance/subgraphs/name/elkfinance/elkdex-okex",
[CHAIN.KCC]: "https://kcc-graph.elk.finance/subgraphs/name/elkfinance/elkdex-kcc",
// [CHAIN.ELASTOS]: "https://elastos-graph.elk.finance/subgraphs/name/elkfinance/elkdex-elastos",
// [CHAIN.OKEXCHAIN]: "https://okex-graph.elk.finance/subgraphs/name/elkfinance/elkdex-okex",
// [CHAIN.KCC]: "https://kcc-graph.elk.finance/subgraphs/name/elkfinance/elkdex-kcc",
[CHAIN.ETHEREUM]: "https://api.thegraph.com/subgraphs/name/elkfinance/elkdex-eth",
[CHAIN.OPTIMISM]: "https://api.thegraph.com/subgraphs/name/elkfinance/elkdex-optimism",
// [CHAIN.CRONOS]: "https://cronos-graph.elk.finance/subgraphs/name/elkfinance/elkdex-cronos",
[CHAIN.FUSE]: "https://fuse-graph.elk.finance/subgraphs/name/elkfinance/elkdex-fuse",
[CHAIN.IOTEX]: "https://iotex-graph.elk.finance/subgraphs/name/elkfinance/elkdex-iotex",
[CHAIN.TELOS]: "https://telos-graph2.elk.finance/subgraphs/name/elkfinance/elkdex-telos"
// [CHAIN.FUSE]: "https://fuse-graph.elk.finance/subgraphs/name/elkfinance/elkdex-fuse",
// [CHAIN.IOTEX]: "https://iotex-graph.elk.finance/subgraphs/name/elkfinance/elkdex-iotex",
// [CHAIN.TELOS]: "https://telos-graph2.elk.finance/subgraphs/name/elkfinance/elkdex-telos"
}, {
factoriesName: "elkFactories",
dayData: "elkDayData",
Expand All @@ -30,13 +30,13 @@ adapter.adapter.bsc.start = 1629251617;
adapter.adapter.fantom.start = 1621562017;
adapter.adapter.polygon.start = 1618019617;
adapter.adapter.xdai.start = 1629251617;
adapter.adapter.elastos.start = 1634954017;
adapter.adapter.okexchain.start = 1649555617;
adapter.adapter.kcc.start = 1634954017;
// adapter.adapter.elastos.start = 1634954017;
// adapter.adapter.okexchain.start = 1649555617;
// adapter.adapter.kcc.start = 1634954017;
adapter.adapter.ethereum.start = 1619747617;
adapter.adapter.optimism.start = 1651542817;
adapter.adapter.fuse.start = 1639187617;
adapter.adapter.iotex.start = 1639792417;
adapter.adapter.telos.start = 1648684800;
// adapter.adapter.fuse.start = 1639187617;
// adapter.adapter.iotex.start = 1639792417;
// adapter.adapter.telos.start = 1648684800;

export default adapter;
8 changes: 6 additions & 2 deletions dexs/hashflow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { httpGet } from "../../utils/fetchURL";
const chains = [CHAIN.ETHEREUM, CHAIN.AVAX, CHAIN.BSC, CHAIN.ARBITRUM, CHAIN.OPTIMISM, CHAIN.POLYGON]

const dateToTs = (date: string) => new Date(date).getTime() / 1000
const normalizeChain = (c: string) => c === "Avalanche" ? "avax" : c.toLowerCase()
const normalizeChain = (c: string) => {
if (c === "bnb") return CHAIN.BSC
if (c === "avalanche") return CHAIN.AVAX
return c
}

interface IAPIResponse {
data: {
Expand Down Expand Up @@ -44,4 +48,4 @@ const adapter: SimpleAdapter = {
}, {} as BaseAdapter)
};

export default adapter;
export default adapter;
2 changes: 1 addition & 1 deletion dexs/native/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const adapter: SimpleAdapter = {
0
);

const dateEntry = response.data.find(
const dateEntry = response.find(
(entry: ResEntry) => entry.date === cleanTimestamp
);
const dailyVol = dateEntry ? dateEntry.volumeUSD : undefined;
Expand Down
2 changes: 1 addition & 1 deletion dexs/starkdefi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const adapter: Adapter = {
adapter: {
[CHAIN.STARKNET]: {
fetch: fetch,
runAtCurrTime: true,
// runAtCurrTime: true,
start: async () => 1700956800,
},
},
Expand Down
13 changes: 9 additions & 4 deletions dexs/vortex-protocol/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ const fetch = async (timestamp: number) => {
}
}

const fethcEmpty = async (timestamp: number) => {
return {
timestamp: timestamp,
}
}

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.TEZOS]: {
fetch: fetch,
start: START_TIME,
customBackfill: customBackfill(CHAIN.TEZOS as Chain, () => fetch)
},
fetch: fethcEmpty,
start: async () => START_TIME,
}
},
};

Expand Down
14 changes: 13 additions & 1 deletion fees/aerodrome/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@ const gurar = '0x2073D8035bB2b0F2e85aAF5a8732C6f397F9ff9b';
const abis: any = {
"forSwaps": "function forSwaps() view returns ((address lp, bool stable, address token0, address token1, address factory)[])"
}
// defualt abi for multiCall is error some pools
const multiCall = async (callN: any) => {
return (await sdk.api.abi.multiCall({
abi: callN.abi,
calls: callN.calls.map((pool: any) => ({
target: pool,
})),
chain: CHAIN.BASE,
permitFailure: true,
})).output.map((r: any) => r.output).flat()
}

const fetch = async (timestamp: number, _: ChainBlocks, fetchOptions: FetchOptions): Promise<FetchResultFees> => {
const forSwaps = await sdk.api2.abi.call({ target: gurar, abi: abis.forSwaps, chain: CHAIN.BASE, })
const pools = forSwaps.map((e: any) => e.lp)

fetchOptions.api.multiCall = multiCall
const res: any = await getDexFees({ chain: CHAIN.BASE, fromTimestamp: fetchOptions.fromTimestamp, toTimestamp: fetchOptions.toTimestamp, pools, timestamp, fetchOptions })
res.dailyBribesRevenue = await fees_bribes(fetchOptions);

return res

}
Expand Down
4 changes: 2 additions & 2 deletions fees/friend3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const fetchOpbnb = (async (timestamp: number, _cb: any, { getLogs, createBalance
dailyFees.addGasToken(i.protocolAmount)
dailyFees.addGasToken(i.subjectAmount)
dailyFees.addGasToken(i.holderAmount)
dailyRevenue.addGasToken(i.protocolEthAmount)
dailyRevenue.addGasToken(i.referralAmount * -1)
dailyRevenue.addGasToken(i?.protocolEthAmount || BigInt(0))
dailyRevenue.addGasToken(BigInt(i.referralAmount * BigInt(-1)))
})
return { dailyFees, dailyRevenue, timestamp }
}) as Fetch
Expand Down
6 changes: 3 additions & 3 deletions fees/velodrome-v2/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Adapter, Fetch, FetchResultFees } from '../../adapters/types';
import { Adapter, Fetch, FetchOptions, FetchResultFees } from '../../adapters/types';
import { CHAIN, OPTIMISM } from '../../helpers/chains';
import { fetchV2 } from './velodrome-v2';
import { fees_bribes } from './bribes';
import { getBlock } from '../../helpers/getBlock';


const getFees = async (timestamp: number): Promise<FetchResultFees> => {
const getFees = async (timestamp: number, _, fetchOptions: FetchOptions): Promise<FetchResultFees> => {
const fromTimestamp = timestamp - 60 * 60 * 24
const toTimestamp = timestamp
const fromBlock = (await getBlock(fromTimestamp, CHAIN.OPTIMISM, {}));
const toBlock = (await getBlock(toTimestamp, CHAIN.OPTIMISM, {}));
const [feeV2, bribes] = await Promise.all([fetchV2(fromBlock, toBlock,timestamp), fees_bribes(fromBlock, toBlock, timestamp)]);
const [feeV2, bribes] = await Promise.all([fetchV2(fromBlock, toBlock,timestamp, fetchOptions), fees_bribes(fromBlock, toBlock, timestamp)]);
const dailyFees = Number(feeV2.dailyFees);
const dailyRevenue = Number(feeV2.dailyRevenue);
const dailyHoldersRevenue = Number(feeV2.dailyHoldersRevenue);
Expand Down
6 changes: 3 additions & 3 deletions fees/velodrome-v2/velodrome-v2.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { FetchResultFees } from "../../adapters/types";
import { FetchOptions, FetchResultFees } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";
import { getDexFees } from "../../helpers/dexVolumeLogs";

const FACTORY_ADDRESS = '0xF1046053aa5682b4F9a81b5481394DA16BE5FF5a';

export const fetchV2 = async (fromBlock: number, toBlock: number, timestamp: number): Promise<FetchResultFees> => {
return getDexFees({ chain: CHAIN.OPTIMISM, fromBlock, toBlock, factory: FACTORY_ADDRESS, timestamp, lengthAbi: 'allPoolsLength', itemAbi: 'allPools' })
export const fetchV2 = async (fromBlock: number, toBlock: number, timestamp: number, fetchOptions: FetchOptions): Promise<FetchResultFees> => {
return getDexFees({ chain: CHAIN.OPTIMISM, fromBlock, toBlock, factory: FACTORY_ADDRESS, timestamp, lengthAbi: 'allPoolsLength', itemAbi: 'allPools', fetchOptions })
}
3 changes: 2 additions & 1 deletion helpers/getBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ const blacklistedChains: string[] = [
"persistence",
"sui",
"neutron",
"terra2"
"terra2",
"ronin"
];

async function getBlock(timestamp: number, chain: Chain, chainBlocks = {} as ChainBlocks) {
Expand Down
4 changes: 2 additions & 2 deletions helpers/getChainFees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ export const getOneDayFees = async (assetID: string, startDate: string, endDate:
throw new Error(`Failed to fetch CoinMetrics data for ${assetID} on ${endDate}`);
}

return parseFloat(result.data.data[0]['FeeTotUSD']);
}
return parseFloat(result.data[0]['FeeTotUSD']);
}
7 changes: 4 additions & 3 deletions utils/fetchURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ function formAxiosError(url: string, error: any, options?: any) {
return e
}

const successCodes: number[] = [200, 201, 202, 203, 204, 205, 206, 207, 208, 226];
export async function httpGet(url: string, options?: AxiosRequestConfig, { withMetadata = false } = {}) {
try {
const res = await axios.get(url, options)
if (res.status !== 200) throw new Error(`Error fetching ${url}: ${res.status} ${res.statusText}`)
if (!successCodes.includes(res.status)) throw new Error(`Error fetching ${url}: ${res.status} ${res.statusText}`)
if (!res.data) throw new Error(`Error fetching ${url}: no data`)
if (withMetadata) return res
return res.data
Expand All @@ -45,10 +46,10 @@ export async function httpGet(url: string, options?: AxiosRequestConfig, { withM
export async function httpPost(url: string, data: any, options?: AxiosRequestConfig) {
try {
const res = await axios.post(url, data, options)
if (res.status !== 200) throw new Error(`Error fetching ${url}: ${res.status} ${res.statusText}`)
if (!successCodes.includes(res.status)) throw new Error(`Error fetching ${url}: ${res.status} ${res.statusText}`)
if (!res.data) throw new Error(`Error fetching ${url}: no data`)
return res.data
} catch (error) {
throw formAxiosError(url, error, { method: 'POST' })
}
}
}

0 comments on commit dc9ac09

Please sign in to comment.