Skip to content

Commit

Permalink
Merge branch 'master' of github.com:FeeFreeFi/dimension-adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
GaussETH committed Dec 18, 2024
2 parents c8cc88a + ef9ced5 commit 362b7a3
Show file tree
Hide file tree
Showing 12 changed files with 335 additions and 45 deletions.
5 changes: 3 additions & 2 deletions dexs/aerodrome-slipstream/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ const fetch = async (fetchOptions: FetchOptions): Promise<FetchResult> => {
let pairs = await api.fetchList({ lengthAbi: 'allPoolsLength', itemAbi: 'allPools', target: '0x5e7BB104d84c7CB9B682AaC2F3d509f5F406809A' })
let token0s = await api.multiCall({ abi: 'address:token0', calls: pairs })
let token1s = await api.multiCall({ abi: 'address:token1', calls: pairs })
const res = await filterPools2({ fetchOptions, pairs, token0s, token1s })
api.log(res.pairs.length, 'pairs out of', pairs.length, chain, 'aerodrome')

const res = await filterPools2({ fetchOptions, pairs, token0s, token1s, minUSDValue: 2000, maxPairSize: 1000 })
pairs = res.pairs
token0s = res.token0s
token1s = res.token1s

const fees = await api.multiCall({ abi: 'uint256:fee', calls: pairs })

let logs: ILog[][] = await getLogs({ targets: pairs, eventAbi: event_swap, flatten: false, })
Expand Down
97 changes: 92 additions & 5 deletions dexs/aerodrome/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,95 @@
import { FetchOptions, FetchResult, SimpleAdapter } from "../../adapters/types"
import { CHAIN } from "../../helpers/chains"
import { uniV2Exports } from "../../helpers/uniswap";
import { addOneToken } from "../../helpers/prices";
import { filterPools2 } from "../../helpers/uniswap";

const swapEvent = 'event Swap(address indexed sender, address indexed to, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out)'
interface ILog {
address: string;
data: string;
transactionHash: string;
topics: string[];
}
const event_swap = 'event Swap(address indexed sender, address indexed to, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out)'

export default uniV2Exports({
[CHAIN.BASE]: { factory: '0x420DD381b31aEf6683db6B902084cB0FFECe40Da', swapEvent, },
})
const fetch = async (fetchOptions: FetchOptions): Promise<FetchResult> => {
const { api, getLogs, createBalances, } = fetchOptions
const chain = api.chain
const dailyVolume = createBalances()
const dailyFees = createBalances()
let pairs = await api.fetchList({ lengthAbi: 'allPoolsLength', itemAbi: 'allPools', target: '0x420DD381b31aEf6683db6B902084cB0FFECe40Da' })
let token0s = await api.multiCall({ abi: 'address:token0', calls: pairs })
let token1s = await api.multiCall({ abi: 'address:token1', calls: pairs })

const res = await filterPools2({ fetchOptions, pairs, token0s, token1s, minUSDValue: 10000, maxPairSize: 1200 })
pairs = res.pairs
token0s = res.token0s
token1s = res.token1s

let stables = await api.multiCall({ abi: 'bool:stable', calls: pairs })

const poolsCalls: any[] = [];
pairs.forEach((pair: any, i) => {
poolsCalls.push({
target: '0x420DD381b31aEf6683db6B902084cB0FFECe40Da',
params: [pair, stables[i]]
})
});

const fees = await api.multiCall({ abi: 'function getFee(address pool, bool _stable) external view returns (uint256)', calls: poolsCalls })

let logs: ILog[][] = [];
const targetChunkSize = 5;
let currentTargetOffset = 0;
let unfinished = true;

while (unfinished) {
let endOffset = currentTargetOffset + targetChunkSize;
if (endOffset >= pairs.length) {
unfinished = false;
endOffset = pairs.length;
}

let currentLogs: ILog[][] = await getLogs({
targets: pairs.slice(currentTargetOffset, endOffset),
eventAbi: event_swap,
flatten: false,
})

logs.push(...currentLogs);
currentTargetOffset += targetChunkSize;
}

logs.forEach((logs: ILog[], idx: number) => {
const token0 = token0s[idx]
const token1 = token1s[idx]
const fee = fees[idx]/1e4

logs.forEach((log: any) => {
let amount0 = log.amount0In;
let amount1 = log.amount1Out;

if (Number(amount0) === 0) {
amount0 = log.amount0out;
amount1 = log.amount1In;
}

let fee0 = Number(amount0) * fee;
let fee1 = Number(amount1) * fee;
addOneToken({ chain, balances: dailyVolume, token0, token1, amount0, amount1 })
addOneToken({ chain, balances: dailyFees, token0, token1, amount0: fee0, amount1: fee1 })
})
})

return { dailyVolume, dailyFees, dailyRevenue: dailyFees, dailyHoldersRevenue: dailyFees } as any
}

const adapters: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.BASE]: {
fetch: fetch as any,
start: '2023-08-28',
}
}
}
export default adapters;
12 changes: 6 additions & 6 deletions dexs/hyperliquid/index.ts → dexs/hyperliquid-perp/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import type { SimpleAdapter } from "../../adapters/types";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";
import { CHAIN } from "../../helpers/chains";
import { httpGet, httpPost } from "../../utils/fetchURL";
import { httpPost } from "../../utils/fetchURL";

const URL = "https://api.hyperliquid.xyz/info";

interface Response {
totalVolume?: number;
dailyVolume?: number;
dayNtlVlm: string;
}

const fetch = async (timestamp: number) => {
const {totalVolume, dailyVolume}: Response = (await httpPost(URL, {"type": "globalStats"}));
const respose: Response[] = (await httpPost(URL, {"type": "metaAndAssetCtxs"}))[1];
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
const dailyVolume = respose.reduce((acc, item) => {
return acc + Number(item.dayNtlVlm);
},0);

return {
totalVolume: totalVolume?.toString(),
dailyVolume: dailyVolume?.toString(),
timestamp: dayTimestamp,
};
Expand Down
33 changes: 33 additions & 0 deletions dexs/hyperliquid-spot/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { SimpleAdapter } from "../../adapters/types";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";
import { httpPost } from "../../utils/fetchURL";

const URL = "https://api.hyperliquid.xyz/info";

interface Response {
dayNtlVlm: string;
}

const fetch = async (timestamp: number) => {
const respose: Response[] = (await httpPost(URL, {"type": "spotMetaAndAssetCtxs"}))[1];
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
const dailyVolume = respose.reduce((acc, item) => {
return acc + Number(item.dayNtlVlm);
},0);

return {
dailyVolume: dailyVolume?.toString(),
timestamp: dayTimestamp,
};
};

const adapter: SimpleAdapter = {
adapter: {
"hyperliquid": {
fetch,
start: '2023-02-25',
},
}
};

export default adapter;
12 changes: 12 additions & 0 deletions dexs/neby-dex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { univ2Adapter } from "../helpers/getUniSubgraphVolume";
import { CHAIN } from "../helpers/chains";

const endpoints = {
[CHAIN.SAPPHIRE]: 'https://api.goldsky.com/api/public/project_clzi4lu67khgw01072ibvekvt/subgraphs/neby-dex-sapphire-mainnet/1.0.0/gn',
};
const adapter = univ2Adapter(endpoints, {
factoriesName: 'factories',
});


export default adapter
43 changes: 38 additions & 5 deletions fees/aerodrome/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
import { FetchOptions, FetchResult, SimpleAdapter } from "../../adapters/types"
import { CHAIN } from "../../helpers/chains"
import { uniV2Exports } from "../../helpers/uniswap";

const swapEvent = 'event Swap(address indexed sender, address indexed to, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out)'
const event_notify_reward = 'event NotifyReward(address indexed from,address indexed reward,uint256 indexed epoch,uint256 amount)';
const event_gauge_created = 'event GaugeCreated(address indexed poolFactory,address indexed votingRewardsFactory,address indexed gaugeFactory,address pool,address bribeVotingReward,address feeVotingReward,address gauge,address creator)'

export default uniV2Exports({
[CHAIN.BASE]: { factory: '0x420DD381b31aEf6683db6B902084cB0FFECe40Da', swapEvent, voter: '0x16613524e02ad97eDfeF371bC883F2F5d6C480A50', maxPairSize: 65, },
})
const fetch = async (fetchOptions: FetchOptions): Promise<FetchResult> => {
const { api, getLogs, createBalances, getToBlock, } = fetchOptions
const chain = api.chain
const voter = '0x16613524e02ad97eDfeF371bC883F2F5d6C480A5';
const dailyBribes = createBalances()
const logs_gauge_created = (await getLogs({
target: voter,
fromBlock: 3200601,
toBlock: await getToBlock(),
eventAbi: event_gauge_created,
cacheInCloud: true,
}))
const bribes_contract: string[] = logs_gauge_created.map((e: any) => e.bribeVotingReward.toLowerCase());

const logs = await getLogs({
targets: bribes_contract,
eventAbi: event_notify_reward,
})
logs.map((e: any) => {
dailyBribes.add(e.reward, e.amount)
})

return { dailyBribesRevenue: dailyBribes } as any
}

const adapters: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.BASE]: {
fetch: fetch as any,
start: '2023-08-28',
}
}
}
export default adapters;
42 changes: 42 additions & 0 deletions fees/neby-dex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { SimpleAdapter } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
import { getGraphDimensions2 } from "../helpers/getUniSubgraph";

const methodology = {
UserFees: "LPs collect 100% of the fee generated in a pool",
Fees: "Fees generated on each swap at a rate set by the pool.",
TotalUserFees: "Cumulative all-time Fees",
TotalFees: "Cumulative all-time Fees",
};

const v3Graphs = getGraphDimensions2({
graphUrls: {
[CHAIN.SAPPHIRE]: "https://api.goldsky.com/api/public/project_clzi4lu67khgw01072ibvekvt/subgraphs/neby-dex-sapphire-mainnet/1.0.0/gn"
},
totalVolume: {
factory: "factories",
},
feesPercent: {
type: "fees",
ProtocolRevenue: 0,
HoldersRevenue: 0,
Fees: 0,
UserFees: 100, // User fees are 100% of collected fees
SupplySideRevenue: 100, // 100% of fees are going to LPs
Revenue: 0, // Revenue is 100% of collected fees
},
});

const adapter: SimpleAdapter = {
version: 2,
adapter: {
[CHAIN.SAPPHIRE]: {
fetch: v3Graphs(CHAIN.SAPPHIRE),
meta: {
methodology,
},
},
},
};

export default adapter;
54 changes: 54 additions & 0 deletions fees/sudofinance/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import fetchURL from '../../utils/fetchURL';
import { FetchResultFees, SimpleAdapter } from '../../adapters/types';
import { CHAIN } from '../../helpers/chains';
import { getUniqStartOfTodayTimestamp } from '../../helpers/getUniSubgraphFees';

const sudoApi = 'https://api.sudofinance.xyz';
const TREASURY_FEE_PERCENTAGE = 0.25;

const fetchSui = async (timestamp: number): Promise<FetchResultFees> => {
const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000));
const {
fee: dailyFee,
tradingFee: dailyTradingFee,
fundingFee: dailyFundingFee,
poolFee: dailyPoolFee,
} = await fetchURL(`${sudoApi}/fee?timestamp=${timestamp}`);
const { totalFee, totalTradingFee, totalFundingFee, totalPoolFee } =
await fetchURL(`${sudoApi}/totalFee`);

const dailyProtocolRevenue =
(Number(dailyTradingFee) || 0) * TREASURY_FEE_PERCENTAGE;
const totalProtocolRevenue =
(Number(totalTradingFee) || 0) * TREASURY_FEE_PERCENTAGE;
const dailySupplySideRevenue =
Number(dailyTradingFee || 0) * (1 - TREASURY_FEE_PERCENTAGE) +
Number(dailyPoolFee || 0) +
Number(dailyFundingFee);
const totalSupplySideRevenue =
Number(totalTradingFee || 0) * (1 - TREASURY_FEE_PERCENTAGE) +
Number(totalPoolFee || 0) +
Number(totalFundingFee);
return {
dailyFees: dailyFee ? `${dailyFee}` : undefined,
totalFees: totalFee ? `${totalFee}` : undefined,
dailyUserFees: dailyFee ? `${dailyFee}` : undefined,
totalUserFees: totalFee ? `${totalFee}` : undefined,
dailySupplySideRevenue: `${dailySupplySideRevenue}`,
totalSupplySideRevenue: `${totalSupplySideRevenue}`,
dailyRevenue: dailyProtocolRevenue ? `${dailyProtocolRevenue}` : undefined,
totalRevenue: totalProtocolRevenue ? `${totalProtocolRevenue}` : undefined,
timestamp: dayTimestamp,
};
};

const adapter: SimpleAdapter = {
adapter: {
[CHAIN.SUI]: {
fetch: fetchSui,
start: '2024-01-05',
},
},
};

export default adapter;
2 changes: 1 addition & 1 deletion fees/toros/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const CONFIG = {
[CHAIN.BASE]: {
endpoint: "https://api.studio.thegraph.com/query/48129/dhedge-v2-base-mainnet/version/latest",
torosManagerAddress: "0x5619ad05b0253a7e647bd2e4c01c7f40ceab0879",
easyswapperAddresses: ["0xe10ed1e5354eed0f7c9d2e16250ba8996c12db7a", "0xa907504d7a4c415b4e6e1d0866d96afe8202f0e5"],
easyswapperAddresses: ["0xe10ed1e5354eed0f7c9d2e16250ba8996c12db7a", "0xf067575eb60c7587c11e867907aa7284833704d1"],
},
};

Expand Down
Loading

0 comments on commit 362b7a3

Please sign in to comment.