-
Notifications
You must be signed in to change notification settings - Fork 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 'DefiLlama:master' into master
- Loading branch information
Showing
8 changed files
with
196 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,89 @@ | ||
import fetchURL from "../../utils/fetchURL"; | ||
import { FetchResult } from "../../adapters/types"; | ||
import { FetchResult, SimpleAdapter, FetchOptions } from "../../adapters/types"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
|
||
const URL = "https://defilama-stats.vooi.workers.dev/"; | ||
const endpoint = ""; | ||
const startTimestamp = 1714608000; // 02.05.2024 | ||
const URL = "https://vooi-rebates.fly.dev/"; | ||
const endpoint = "defillama/volumes"; | ||
const startTimestampArbitrum = 1714608000; // 02.05.2024 | ||
const startTimestampBlast = 1719792000; // 01.07.2024 | ||
const startTimestampOpBNB = 1717200000; // 01.06.2024 | ||
const startTimestampBase = 1722470400; // 01.08.2024 | ||
|
||
const fetchArbitrum = async (options: FetchOptions): Promise<FetchResult> => { | ||
const timestamp = options.toTimestamp | ||
const fetchData = await fetchURL(`${URL}${endpoint}?ts=${timestamp}`) | ||
const orderlyItem = fetchData.find(((item) => item.protocol == "orderly")) | ||
if (!orderlyItem) return {dailyVolume: 0, totalVolume: 0, timestamp} | ||
const dailyVolume = orderlyItem.dailyVolume | ||
const totalVolume = orderlyItem.totalVolume | ||
return { | ||
dailyVolume, | ||
totalVolume, | ||
timestamp | ||
}; | ||
}; | ||
|
||
interface IAPIResponse { | ||
dailyVolume: string; | ||
totalVolume: string; | ||
} | ||
const fetch = async (timestamp: number): Promise<FetchResult> => { | ||
const { dailyVolume, totalVolume }: IAPIResponse = ( | ||
(await fetchURL(`${URL}${endpoint}?ts=${timestamp}`)).data | ||
); | ||
const fetchBlast = async (options: FetchOptions): Promise<FetchResult> => { | ||
const timestamp = options.toTimestamp | ||
const fetchData = await fetchURL(`${URL}${endpoint}?ts=${timestamp}`) | ||
const synfuturesItem = fetchData.find(((item) => item.protocol == "synfutures" && item.network == "blast")) | ||
if (!synfuturesItem) return {dailyVolume: 0, totalVolume: 0, timestamp} | ||
const dailyVolume = synfuturesItem.dailyVolume | ||
const totalVolume = synfuturesItem.totalVolume | ||
return { | ||
timestamp, | ||
dailyVolume, | ||
totalVolume, | ||
timestamp | ||
}; | ||
}; | ||
|
||
export default { | ||
const fetchBase = async (options: FetchOptions): Promise<FetchResult> => { | ||
const timestamp = options.toTimestamp | ||
const fetchData = await fetchURL(`${URL}${endpoint}?ts=${timestamp}`) | ||
const synfuturesItem = fetchData.find(((item) => item.protocol == "synfutures" && item.network == "base")) | ||
if (!synfuturesItem) return {dailyVolume: 0, totalVolume: 0, timestamp} | ||
const dailyVolume = synfuturesItem.dailyVolume | ||
const totalVolume = synfuturesItem.totalVolume | ||
return { | ||
dailyVolume, | ||
totalVolume, | ||
timestamp | ||
}; | ||
}; | ||
|
||
const fetchOpBNB = async (options: any): Promise<FetchResult> => { | ||
const timestamp = options.toTimestamp | ||
const fetchData = await fetchURL(`${URL}${endpoint}?ts=${timestamp}`) | ||
const kiloexItem = fetchData.find(((item) => item.protocol == "kiloex")) | ||
if (!kiloexItem) return {dailyVolume: 0, totalVolume: 0, timestamp} | ||
const dailyVolume = kiloexItem.dailyVolume | ||
const totalVolume = kiloexItem.totalVolume | ||
return { | ||
dailyVolume, | ||
totalVolume, | ||
timestamp | ||
}; | ||
}; | ||
|
||
const adapter: SimpleAdapter = { | ||
adapter: { | ||
[CHAIN.ARBITRUM]: { | ||
fetch: fetch, | ||
start: startTimestamp | ||
fetch: fetchArbitrum, | ||
start: startTimestampArbitrum | ||
}, | ||
[CHAIN.BLAST]: { | ||
fetch: fetchBlast, | ||
start: startTimestampBlast | ||
}, | ||
[CHAIN.OP_BNB]: { | ||
fetch: fetchOpBNB, | ||
start: startTimestampOpBNB | ||
}, | ||
[CHAIN.BASE]: { | ||
fetch: fetchBase, | ||
start: startTimestampBase | ||
}, | ||
}, | ||
// version: 2 // data accepts only one input to timestamp | ||
version: 2 | ||
} | ||
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
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
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
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,61 @@ | ||
import { ChainBlocks, FetchOptions, IJSON, SimpleAdapter } from "../../adapters/types"; | ||
import { CHAIN } from "../../helpers/chains"; | ||
import { addOneToken } from "../../helpers/prices"; | ||
import { filterPools } from "../../helpers/uniswap"; | ||
|
||
const event_swap = 'event Swap(address indexed sender, address indexed to, uint24 id, bytes32 amountsIn, bytes32 amountsOut, uint24 volatilityAccumulator, bytes32 totalFees, bytes32 protocolFees)'; | ||
const FACTORY_ADDRESS = '0x8Cce20D17aB9C6F60574e678ca96711D907fD08c'; | ||
|
||
type TABI = { | ||
[k: string]: string; | ||
} | ||
const ABIs: TABI = { | ||
"getNumberOfLBPairs": "uint256:getNumberOfLBPairs", | ||
"getLBPairAtIndex": "function getLBPairAtIndex(uint256 index) view returns (address lbPair)" | ||
} | ||
|
||
const fetch: any = async (timestamp: number, _: ChainBlocks, { getLogs, api, createBalances }: FetchOptions) => { | ||
const dailyVolume = createBalances(); | ||
const dailyFees = createBalances(); | ||
const dailyRevenue = createBalances(); | ||
const lpTokens = await api.fetchList({ lengthAbi: ABIs.getNumberOfLBPairs, itemAbi: ABIs.getLBPairAtIndex, target: FACTORY_ADDRESS }) | ||
const [tokens0, tokens1] = await Promise.all(['address:getTokenX', 'address:getTokenY'].map((abi: string) => api.multiCall({ abi, calls: lpTokens }))); | ||
|
||
|
||
const pairObject: IJSON<string[]> = {} | ||
lpTokens.forEach((pair: string, i: number) => { | ||
pairObject[pair] = [tokens0[i], tokens1[i]] | ||
}) | ||
|
||
// filter out the pairs with less than 1000 USD pooled value | ||
const filteredPairs = await filterPools({ api: api, pairs: pairObject, createBalances: createBalances }) | ||
await Promise.all(Object.keys(filteredPairs).map(async (pair) => { | ||
const [token0, token1] = pairObject[pair] | ||
const logs = await getLogs({ target: pair, eventAbi: event_swap }) | ||
logs.forEach(log => { | ||
const amountInX = Number('0x' + '0'.repeat(32) + log.amountsOut.replace('0x', '').slice(0, 32)) | ||
const amountInY = Number('0x' + '0'.repeat(32) + log.amountsOut.replace('0x', '').slice(32, 64)) | ||
dailyVolume.add(token1, amountInX); | ||
dailyVolume.add(token0, amountInY); | ||
|
||
const protocolFeesY = Number('0x' + log.protocolFees.replace('0x', '').slice(0, 32)) | ||
const protocolFeesX = Number('0x' + log.protocolFees.replace('0x', '').slice(32, 64)) | ||
const totalFeesY = Number('0x' + log.totalFees.replace('0x', '').slice(0, 32)); | ||
const totalFeesX = Number('0x' + log.totalFees.replace('0x', '').slice(32, 64)); | ||
dailyFees.add(token0, totalFeesX ) | ||
dailyFees.add(token1, totalFeesY ) | ||
dailyRevenue.add(token0, protocolFeesX) | ||
dailyRevenue.add(token1, protocolFeesY) | ||
}) | ||
})) | ||
|
||
return { dailyVolume, dailyFees, dailyRevenue, timestamp }; | ||
} | ||
|
||
const adapter: SimpleAdapter = { | ||
adapter: { | ||
[CHAIN.IOTAEVM]: { fetch, start: 1681130543, }, | ||
} | ||
}; | ||
|
||
export default adapter; |