Skip to content

Commit

Permalink
Merge pull request #797 from DefiLlama/lybra-v2
Browse files Browse the repository at this point in the history
add fees lybra-v2
  • Loading branch information
dtmkeng authored Sep 4, 2023
2 parents afd0e97 + 5f7ecd5 commit e2edca0
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions fees/lybra-v2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { FetchResultFees, SimpleAdapter } from "../adapters/types";
import { CHAIN } from "../helpers/chains";
import * as sdk from "@defillama/sdk";
import { getBlock } from "../helpers/getBlock";
import { getPrices } from "../utils/prices";
import { Chain } from "@defillama/sdk/build/general";
import { ethers } from "ethers";


const address = '0xa980d4c0C2E48d305b582AA439a3575e3de06f0E'
const topic0_fees_distibute = '0xec0804e8e1decb589af9c4ba8ebfbacd3be98929d4d53457dfd186061f489f04';
const event_fees_distibute = 'event FeeDistribution(address indexed feeAddress,uint256 feeAmount,uint256 timestamp)';
const contract_interface = new ethers.utils.Interface([
event_fees_distibute
]);

const fetch = async (timestamp: number): Promise<FetchResultFees> => {
const fromTimestamp = timestamp - 60 * 60 * 24
const toTimestamp = timestamp
try {
const fromBlock = (await getBlock(fromTimestamp, CHAIN.ETHEREUM, {}));
const toBlock = (await getBlock(toTimestamp, CHAIN.ETHEREUM, {}));
const dailyFees = (await sdk.api.util.getLogs({
target: address,
fromBlock: fromBlock,
toBlock: toBlock,
topic: '',
topics: [topic0_fees_distibute],
keys: [],
chain: CHAIN.ETHEREUM
})).output.map((e: any) => contract_interface.parseLog(e))
.map((e: any) => {
return Number(e.args.feeAmount) / 10 ** 18;
}).reduce((a: number, b: number) => a + b,0)
const dailyRevenue = dailyFees;
const dailyHoldersRevenue = dailyFees;
return {
dailyFees: `${dailyFees}`,
dailyRevenue: `${dailyRevenue}`,
dailyHoldersRevenue: `${dailyHoldersRevenue}`,
timestamp
}
} catch(error) {
console.error(error);
throw error;
}

}


const adapter: SimpleAdapter = {
adapter: {
[CHAIN.ETHEREUM]: {
fetch: fetch,
start: async () => 1692921600,
},
}
};

export default adapter;

0 comments on commit e2edca0

Please sign in to comment.