Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
darthgus committed Dec 13, 2024
2 parents fb93bef + 6ce5976 commit 7e8cc05
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 10 deletions.
11 changes: 3 additions & 8 deletions aggregators/swap-coffee/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
import { Adapter, FetchV2 } from "../../adapters/types";
import { httpGet } from "../../utils/fetchURL";
import { CHAIN } from "../../helpers/chains";
import { DAY, getTimestampAtStartOfDay } from "../../utils/date";

const statisticsEndpoint = "https://backend.swap.coffee/v1/statistics/generic"

const fetch: FetchV2 = async ({startTimestamp}) => {
const start = getTimestampAtStartOfDay(startTimestamp)
const end = start + DAY

const fetch: FetchV2 = async ({startTimestamp, endTimestamp}) => {
const statistics = await httpGet(
statisticsEndpoint,
{
params: {
from: start,
to: end
from: startTimestamp,
to: endTimestamp - 1
}
})

return {
timestamp: end,
dailyVolume: statistics?.volume,
dailyFees: statistics?.fees,
};
Expand Down
93 changes: 93 additions & 0 deletions aggregators/swing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { httpGet } from "../../utils/fetchURL";
import { CHAIN } from "../../helpers/chains";
import { FetchOptions, SimpleAdapter } from "../../adapters/types";
import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume";

const chains: Record<string, string> = {
[CHAIN.SOLANA]: 'solana',
[CHAIN.ETHEREUM]: 'ethereum',
[CHAIN.BSC]: 'bsc',
[CHAIN.AVAX]: 'avalanche',
[CHAIN.POLYGON]: 'polygon',
[CHAIN.ARBITRUM]: 'arbitrum',
[CHAIN.ARCHWAY]: 'archway-1',
[CHAIN.BSQUARED]: 'b2-network',
[CHAIN.BASE]: 'base',
[CHAIN.BITCOIN]: 'bitcoin',
[CHAIN.BITLAYER]: 'bitlayer',
[CHAIN.BLAST]: 'blast',
[CHAIN.BOB]: 'bob',
[CHAIN.CORE]: 'core-blockchain',
[CHAIN.COSMOS]: 'cosmoshub-4',
[CHAIN.FANTOM]: 'fantom',
[CHAIN.XDAI]: 'gnosis',
[CHAIN.GRAVITY]: 'gravity',
[CHAIN.INJECTIVE]: 'injective-1',
[CHAIN.LINEA]: 'linea',
[CHAIN.MANTA]: 'manta-pacific',
[CHAIN.MANTLE]: 'mantle',
[CHAIN.METIS]: 'metis',
[CHAIN.MODE]: 'mode',
[CHAIN.MOONBEAM]: 'moonbeam',
[CHAIN.MORPH]: 'morph',
[CHAIN.CELESTIA]: 'cataclysm-1',
[CHAIN.OPTIMISM]: 'optimism',
[CHAIN.OSMOSIS]: 'osmosis-1',
[CHAIN.SCROLL]: 'scroll',
[CHAIN.TAIKO]: 'taiko',
[CHAIN.WC]: 'world-chain',
[CHAIN.ZKSYNC]: 'zksync-era',
};

const fetch = async (_a: any, _b: any, options: FetchOptions) => {
const unixTimestamp = getUniqStartOfTodayTimestamp(
new Date(options.startOfDay * 1000)
);

const dailyRes = await httpGet("https://swap.prod.swing.xyz/v0/metrics/stats", {
headers: {
'Content-Type': 'application/json',
},
params: { startDate: unixTimestamp },
});

const chainVolumes = dailyRes?.historicalVolumeByChain?.map((history: any) => {
const chainVol = history?.volume.find((vol: any) => {
return vol?.chainSlug.toLowerCase() === chains[options.chain].toLowerCase();
})

return chainVol;
});

// calculate the total volume
const chainVol = chainVolumes?.reduce((acc: number, curr: any) => {
return acc + Number(curr?.value || 0);
}, 0);


return {
dailyVolume: chainVol || 0,
};
};

const startDate = '2022-11-01'
const chainAdapters = {
...Object.entries(chains).reduce((acc, chain) => {
const [key, value] = chain;
return {
...acc,
[key]: {
fetch: fetch,
start: startDate

},
};
}, {})
}

const adapter = {
version: 1,
adapter: chainAdapters
};

export default adapter;
57 changes: 57 additions & 0 deletions dexs/balancer-v3/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import request from "graphql-request";
import { FetchOptions, SimpleAdapter } from "../../adapters/types";
import { CHAIN } from "../../helpers/chains";


const adapter: SimpleAdapter = {
version: 2,
adapter: {}
};

const v3ChainMapping: any = {
[CHAIN.ETHEREUM]: 'MAINNET',
[CHAIN.XDAI]: 'GNOSIS',
}

Object.keys(v3ChainMapping).forEach((chain: any) => {
adapter.adapter[chain] = { fetch, runAtCurrTime: true, }
})

// chains = ["MAINNET", "ARBITRUM", "AVALANCHE", "BASE", "GNOSIS", "POLYGON", "ZKEVM", "OPTIMISM", "MODE", "FRAXTAL"]

async function fetch({ createBalances, chain}: FetchOptions) {
const dailyVolume = createBalances()
const dailyFees = createBalances()
const query = `query {
pools: poolGetPools(
first: 1000
skip: 0
orderBy: volume24h
orderDirection: desc
where: { chainIn: [${v3ChainMapping[chain]}] protocolVersionIn: [3]}
) {
address
chain
createTime
decimals
protocolVersion
tags
dynamicData {
totalLiquidity
lifetimeVolume
lifetimeSwapFees
volume24h
fees24h
}
}
}`
const { pools } = await request('https://api-v3.balancer.fi/graphql', query);
pools.forEach((pool: any) => {
dailyFees.addUSDValue(+pool.dynamicData.fees24h)
dailyVolume.addUSDValue(+pool.dynamicData.volume24h)
})
return { dailyFees, dailyVolume }
}


export default adapter;
2 changes: 2 additions & 0 deletions fees/balancer-v3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import adapter from "../dexs/balancer-v3"
export default adapter;
3 changes: 2 additions & 1 deletion fees/superchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const fees: any = {
'0xe900b3Edc1BA0430CFa9a204A1027B90825ac951',
'0xed4811010a86f7c39134fbc20206d906ad1176b6',
'0x13f37e6b638ca83e7090bb3722b3ae04bf884019',
'0x99c9fc46f92e8a1c0dec1b1747d010903e884be1'
'0x99c9fc46f92e8a1c0dec1b1747d010903e884be1',
'0xC2eC5Dd60CBD5242b8cdeB9d0d37Ff6024584631',
]
}
const fetchFees = async (options: FetchOptions) => {
Expand Down
2 changes: 1 addition & 1 deletion fees/swing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const meta = {
methodology: {
UserFees: "Users pays 0.3% of each bridge. The exact fee is calculated based on the partner fee configuration but not over 10%.",
Fees: "A 0.3% bridge fee is collected",
Revenue: "100% of the fee collected, 85%% of the fee collected to partners, 15% of the fee collected to treasury",
Revenue: "100% of the fee collected, 85% of the fee collected to partners, 15% of the fee collected to treasury",
ProtocolRevenue: "A 15% of the fee collected to treasury",
}
};
Expand Down

0 comments on commit 7e8cc05

Please sign in to comment.