-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:FeeFreeFi/dimension-adapters
- Loading branch information
Showing
12 changed files
with
335 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.