-
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.
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { FetchResultFees, SimpleAdapter } from "../adapters/types" | ||
import { CHAIN } from "../helpers/chains" | ||
import { getBlock } from "../helpers/getBlock"; | ||
import * as sdk from "@defillama/sdk"; | ||
|
||
const topic0_evt_transfer = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'; | ||
const topic1_evt_transfer = '0x000000000000000000000000bbc843dcb1009bc7dc988bceb5bb1b50299d9a6d'; | ||
const topic2_evt_transfer = '0x0000000000000000000000006ced48efbb581a141667d7487222e42a3fa17cf7'; | ||
const usdc = '0x2791bca1f2de4661ed88a30c99a7a9449aa84174'; | ||
|
||
interface ILog { | ||
data: string; | ||
transactionHash: string; | ||
topics: string[]; | ||
address: string; | ||
} | ||
|
||
const fetchFees = async (timestamp: number): Promise<FetchResultFees> => { | ||
const toTimestamp = timestamp; | ||
const fromTimestamp = timestamp - 60 * 60 * 24; | ||
try { | ||
const fromBlock = (await getBlock(fromTimestamp, CHAIN.POLYGON, {})); | ||
const toBlock = (await getBlock(toTimestamp, CHAIN.POLYGON, {})); | ||
|
||
const logs: ILog[] = (await sdk.api.util.getLogs({ | ||
target: usdc, | ||
topic: '', | ||
toBlock: toBlock, | ||
fromBlock: fromBlock, | ||
keys: [], | ||
chain: CHAIN.POLYGON, | ||
topics: [topic0_evt_transfer, topic1_evt_transfer, topic2_evt_transfer] | ||
})).output as ILog[]; | ||
const dailyFees = logs.reduce((acc: number, log: ILog) => { | ||
const amount = Number(log.data) / 10 ** 6; | ||
return acc + amount; | ||
}, 0); | ||
return { | ||
dailyFees: `${dailyFees}`, | ||
dailyHoldersRevenue: `${dailyFees}`, | ||
dailyRevenue: `${dailyFees}`, | ||
timestamp | ||
} | ||
} catch (error) { | ||
console.error(error) | ||
throw error; | ||
} | ||
} | ||
|
||
const adapter: SimpleAdapter = { | ||
adapter: { | ||
[CHAIN.POLYGON]: { | ||
fetch: fetchFees, | ||
start: async () => 1692144000, | ||
} | ||
} | ||
} | ||
export default adapter |