From b1caf88ce62ff55fb21eaef014244b2a654bff6d Mon Sep 17 00:00:00 2001 From: 0xpeluche <0xpeluche@protonmail.com> Date: Thu, 22 Aug 2024 12:22:45 +0200 Subject: [PATCH 1/2] feat:Adapter, OpenEden-t-bills Fees --- fees/openeden-t-bills/index.ts | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 fees/openeden-t-bills/index.ts diff --git a/fees/openeden-t-bills/index.ts b/fees/openeden-t-bills/index.ts new file mode 100644 index 0000000000..5f6454ca96 --- /dev/null +++ b/fees/openeden-t-bills/index.ts @@ -0,0 +1,65 @@ +// https://docs.openeden.com/treasury-bills-vault/fees + +import { Chain } from "@defillama/sdk/build/general"; +import { Adapter, FetchOptions } from "../../adapters/types"; +import { CHAIN } from "../../helpers/chains"; +import ADDRESSES from "../../helpers/coreAssets.json"; + +const eventAbi = `event ProcessDeposit( + address sender, + address receiver, + uint256 assets, + uint256 shares, + uint256 oeFee, + uint256 pFee, + uint256 totalFee, + address oplTreasury, + address treasury +)`; + +const VAULT_ADDRESSES: Record = { + [CHAIN.ETHEREUM]: "0xdd50C053C096CB04A3e3362E2b622529EC5f2e8a", + [CHAIN.ARBITRUM]: "0xF84D28A8D28292842dD73D1c5F99476A80b6666A", +}; + +const MANAGEMENT_FEES: number = 0.003; +const DAILY_MANAGEMENT_FEES: number = MANAGEMENT_FEES / 365; + +const fetch = async ( + vault: string, + { api, getLogs, createBalances }: FetchOptions +) => { + const dailyFees = createBalances(); + + const [logs, totalUSDC] = await Promise.all([ + getLogs({ target: vault, eventAbi }), + api.call({ target: vault, abi: "uint256:totalAssets" }), + ]); + + dailyFees.add(ADDRESSES[api.chain].USDC, totalUSDC * DAILY_MANAGEMENT_FEES); + + logs.forEach((log) => { + const feeAmount = log[4]; + dailyFees.add(ADDRESSES[api.chain].USDC, feeAmount); + }); + + return { dailyFees }; +}; + +const adapter: Adapter = { + version: 2, + adapter: { + [CHAIN.ETHEREUM]: { + fetch: (options: FetchOptions) => + fetch(VAULT_ADDRESSES[CHAIN.ETHEREUM], options), + start: 1697580000, + }, + [CHAIN.ARBITRUM]: { + fetch: (options: FetchOptions) => + fetch(VAULT_ADDRESSES[CHAIN.ARBITRUM], options), + start: 1707778800, + }, + }, +}; + +export default adapter; From c102f76d4b81608ef88d94d9caed1abd618a9635 Mon Sep 17 00:00:00 2001 From: 0xpeluche <0xpeluche@protonmail.com> Date: Thu, 22 Aug 2024 12:23:44 +0200 Subject: [PATCH 2/2] promise type --- fees/openeden-t-bills/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fees/openeden-t-bills/index.ts b/fees/openeden-t-bills/index.ts index 5f6454ca96..ebc9e37d0c 100644 --- a/fees/openeden-t-bills/index.ts +++ b/fees/openeden-t-bills/index.ts @@ -1,7 +1,7 @@ // https://docs.openeden.com/treasury-bills-vault/fees import { Chain } from "@defillama/sdk/build/general"; -import { Adapter, FetchOptions } from "../../adapters/types"; +import { Adapter, FetchOptions, FetchResultV2 } from "../../adapters/types"; import { CHAIN } from "../../helpers/chains"; import ADDRESSES from "../../helpers/coreAssets.json"; @@ -28,7 +28,7 @@ const DAILY_MANAGEMENT_FEES: number = MANAGEMENT_FEES / 365; const fetch = async ( vault: string, { api, getLogs, createBalances }: FetchOptions -) => { +): Promise => { const dailyFees = createBalances(); const [logs, totalUSDC] = await Promise.all([