Skip to content

Commit

Permalink
add caviar-tangible fees
Browse files Browse the repository at this point in the history
  • Loading branch information
dtmkeng committed Sep 25, 2023
1 parent fdb50f9 commit 755ac3b
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions fees/caviar-tangible.ts
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

0 comments on commit 755ac3b

Please sign in to comment.