From 1bed54b82a79607d343d7becebd8907c0693e86c Mon Sep 17 00:00:00 2001 From: Jenelyn Castil Contillo Date: Mon, 7 Oct 2024 13:39:25 +0800 Subject: [PATCH 1/3] Added wise-lending-v2 fees --- fees/wise-lending-v2/index.ts | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 fees/wise-lending-v2/index.ts diff --git a/fees/wise-lending-v2/index.ts b/fees/wise-lending-v2/index.ts new file mode 100644 index 0000000000..68195b3c63 --- /dev/null +++ b/fees/wise-lending-v2/index.ts @@ -0,0 +1,39 @@ +import { SimpleAdapter } from "../../adapters/types"; +import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; +import { httpGet } from "../../utils/fetchURL"; + +const feesEndpoint = "https://data.wisetoken.net/WISE/globals/fees.json"; + +interface IFeeResponse { + totals: { + totalFeeTokensUSD: number; + }; + tokens: { + [key: string]: { feeTokensUSD: number }; + }; +} + +const fetch = () => { + return async (timestamp: number) => { + const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)); + const fees: IFeeResponse = await httpGet(feesEndpoint); + + return { + dailyFees: `${fees?.totals.totalFeeTokensUSD || undefined}`, + timestamp: dayTimestamp, + }; + }; +}; + +const adapter: SimpleAdapter = { + version: 2, + adapter: { + ["arbitrum"]: { + fetch: fetch(), + runAtCurrTime: true, + start: 1727740800, + }, + }, +}; + +export default adapter; From ee9432a88a7e51ca6a15d1d1c1419d05723e50da Mon Sep 17 00:00:00 2001 From: Jenelyn Castil Contillo Date: Thu, 10 Oct 2024 21:35:15 +0800 Subject: [PATCH 2/3] Updated logic for calculating fees of wise-lending-v2 --- fees/wise-lending-v2/index.ts | 49 +++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/fees/wise-lending-v2/index.ts b/fees/wise-lending-v2/index.ts index 68195b3c63..f12748805b 100644 --- a/fees/wise-lending-v2/index.ts +++ b/fees/wise-lending-v2/index.ts @@ -1,35 +1,40 @@ -import { SimpleAdapter } from "../../adapters/types"; -import { getUniqStartOfTodayTimestamp } from "../../helpers/getUniSubgraphVolume"; -import { httpGet } from "../../utils/fetchURL"; +import { FetchOptions, SimpleAdapter } from "../../adapters/types"; +import { ARBITRUM } from "../../helpers/chains"; +const feeMaangerContract = "0x90a022796798f9dbA1Da0f8645234B284d4E8EC6"; -const feesEndpoint = "https://data.wisetoken.net/WISE/globals/fees.json"; +const arbitrumPools = [ + //aave + "0xe50fA9b3c56FfB159cB0FCA61F5c9D750e8128c8", + "0x6ab707Aca953eDAeFBc4fD23bA73294241490620", + "0x724dc807b04555b71ed48a6896b6F41593b8C637", + "0x82E64f49Ed5EC1bC6e43DAD4FC8Af9bb3A2312EE", + //native + "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9", + "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", + "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", + "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", + "0x5979D7b546E38E414F7E9822514be443A4800529", +]; -interface IFeeResponse { - totals: { - totalFeeTokensUSD: number; - }; - tokens: { - [key: string]: { feeTokensUSD: number }; - }; -} +const fetch: any = async ({ api }: FetchOptions) => { + const feeAmounts = await api.multiCall({ + abi: "function feeTokens(address) view returns (uint256)", + target: feeMaangerContract, + calls: arbitrumPools, + }); -const fetch = () => { - return async (timestamp: number) => { - const dayTimestamp = getUniqStartOfTodayTimestamp(new Date(timestamp * 1000)); - const fees: IFeeResponse = await httpGet(feesEndpoint); + api.add(arbitrumPools, feeAmounts); - return { - dailyFees: `${fees?.totals.totalFeeTokensUSD || undefined}`, - timestamp: dayTimestamp, - }; + return { + dailyFees: await api.getUSDValue(), }; }; const adapter: SimpleAdapter = { version: 2, adapter: { - ["arbitrum"]: { - fetch: fetch(), + [ARBITRUM]: { + fetch, runAtCurrTime: true, start: 1727740800, }, From 37b0742305a79b558c4ed53f40dd435c4f3706db Mon Sep 17 00:00:00 2001 From: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com> Date: Tue, 15 Oct 2024 01:32:32 +0200 Subject: [PATCH 3/3] code refactor --- fees/wise-lending-v2/index.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/fees/wise-lending-v2/index.ts b/fees/wise-lending-v2/index.ts index f12748805b..3c6af605e4 100644 --- a/fees/wise-lending-v2/index.ts +++ b/fees/wise-lending-v2/index.ts @@ -16,18 +16,18 @@ const arbitrumPools = [ "0x5979D7b546E38E414F7E9822514be443A4800529", ]; -const fetch: any = async ({ api }: FetchOptions) => { - const feeAmounts = await api.multiCall({ - abi: "function feeTokens(address) view returns (uint256)", - target: feeMaangerContract, - calls: arbitrumPools, - }); +const fetch: any = async ({ api, fromApi, createBalances, }: FetchOptions) => { + const dailyFees = createBalances() + const totalFees = createBalances() + const feeAmounts = await api.multiCall({ abi: "function feeTokens(address) view returns (uint256)", target: feeMaangerContract, calls: arbitrumPools, permitFailure: true, }); + const feeAmountsADayAgo = await fromApi.multiCall({ abi: "function feeTokens(address) view returns (uint256)", target: feeMaangerContract, calls: arbitrumPools, permitFailure: true, }); - api.add(arbitrumPools, feeAmounts); - return { - dailyFees: await api.getUSDValue(), - }; + dailyFees.add(arbitrumPools, feeAmounts.map(i => i ?? 0)); + totalFees.add(arbitrumPools, feeAmounts.map(i => i ?? 0)); + dailyFees.add(arbitrumPools, feeAmountsADayAgo.map(i => (i ?? 0) * -1)); + + return { dailyFees, totalFees, } }; const adapter: SimpleAdapter = { @@ -35,7 +35,6 @@ const adapter: SimpleAdapter = { adapter: { [ARBITRUM]: { fetch, - runAtCurrTime: true, start: 1727740800, }, },