From 366b9b3551d7b94c6928040a5744b690de098003 Mon Sep 17 00:00:00 2001 From: Antonio Guilherme Ferreira Viggiano Date: Wed, 17 Jul 2024 16:04:51 -0300 Subject: [PATCH 1/2] Add SizeCredit fees --- fees/size-credit.ts | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 fees/size-credit.ts diff --git a/fees/size-credit.ts b/fees/size-credit.ts new file mode 100644 index 0000000000..1075b7104a --- /dev/null +++ b/fees/size-credit.ts @@ -0,0 +1,68 @@ +import ADDRESSES from '../helpers/coreAssets.json'; +import { Adapter, FetchOptions } from "../adapters/types"; +import { CHAIN } from "../helpers/chains"; + +const SZWETH_CONTRACT = '0x974583f05de1fd18c59c77c4a8803cf0c7db5333'; +const SZAUSDC_CONTRACT = '0x38978038a06a21602a4202dfa66968e7f525bf3e'; +const AUSDC_CONTRACT = '0x4e65fe4dba92790696d040ac24aa414708f5c0ab'; +const SIZE_PROXY_CONTRACT = '0xC2a429681CAd7C1ce36442fbf7A4a68B11eFF940'; + +const fetch: any = async ({ createBalances, getLogs, api, getFromBlock, getToBlock }: FetchOptions) => { + const fees = createBalances() + const [fromBlock, toBlock] = await Promise.all([getFromBlock(), getToBlock()]) + const FEE_MAPPING = [ + ADDRESSES.base.WETH, + AUSDC_CONTRACT + ] + const logsArray = await Promise.all([ + getLogs({ + target: SZWETH_CONTRACT, + eventAbi: "event Transfer(address indexed from, address indexed to, uint256 value)", + fromBlock, + toBlock + }), + getLogs({ + target: SZAUSDC_CONTRACT, + eventAbi: "event TransferUnscaled(address indexed from, address indexed to, uint256 value)", + fromBlock, + toBlock + }) + ]) + const feeConfig = await api.call({ + target: SIZE_PROXY_CONTRACT, + abi: "function feeConfig() view returns (uint256 swapFeeAPR, uint256 fragmentationFee, uint256 liquidationRewardPercent, uint256 overdueCollateralProtocolPercent, uint256 collateralProtocolPercent, address feeRecipient)", + params: [], + }); + const feeRecipient = feeConfig.feeRecipient; + logsArray.forEach((logs, i) => { + logs.forEach((log) => { + if (log.to === feeRecipient) { + fees.add(FEE_MAPPING[i], Number(log.value)); + } + }) + }) + + return { + dailyFees: fees, + dailyProtocolRevenue: fees + }; +}; + +const methodology = "Swap fees are applied on every cash-for-credit trade, and fragmentation fees are charged on every credit split" + +const adapter: Adapter = { + version: 2, + adapter: { + [CHAIN.BASE]: { + fetch, + start: 1721083903, + meta: { + methodology: { + Fees: methodology, + ProtocolRevenue: methodology + } + } + }, + } +} +export default adapter; \ No newline at end of file From eced3352957dd211e0af8e379b6b7ef540cf2e25 Mon Sep 17 00:00:00 2001 From: 0xgnek <0xgnek@gmail.com> Date: Mon, 22 Jul 2024 06:01:48 +0000 Subject: [PATCH 2/2] fix fees and token price --- fees/size-credit.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fees/size-credit.ts b/fees/size-credit.ts index 1075b7104a..76cb78579a 100644 --- a/fees/size-credit.ts +++ b/fees/size-credit.ts @@ -4,7 +4,7 @@ import { CHAIN } from "../helpers/chains"; const SZWETH_CONTRACT = '0x974583f05de1fd18c59c77c4a8803cf0c7db5333'; const SZAUSDC_CONTRACT = '0x38978038a06a21602a4202dfa66968e7f525bf3e'; -const AUSDC_CONTRACT = '0x4e65fe4dba92790696d040ac24aa414708f5c0ab'; +const AUSDC_CONTRACT = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'; const SIZE_PROXY_CONTRACT = '0xC2a429681CAd7C1ce36442fbf7A4a68B11eFF940'; const fetch: any = async ({ createBalances, getLogs, api, getFromBlock, getToBlock }: FetchOptions) => { @@ -36,7 +36,7 @@ const fetch: any = async ({ createBalances, getLogs, api, getFromBlock, getToBlo const feeRecipient = feeConfig.feeRecipient; logsArray.forEach((logs, i) => { logs.forEach((log) => { - if (log.to === feeRecipient) { + if (log.to.toLowerCase() === feeRecipient.toLowerCase()) { fees.add(FEE_MAPPING[i], Number(log.value)); } }) @@ -44,6 +44,7 @@ const fetch: any = async ({ createBalances, getLogs, api, getFromBlock, getToBlo return { dailyFees: fees, + dailyRevenue: fees, dailyProtocolRevenue: fees }; }; @@ -65,4 +66,4 @@ const adapter: Adapter = { }, } } -export default adapter; \ No newline at end of file +export default adapter;