-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1682 from aviggiano/master
Add SizeCredit fees
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
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 = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'; | ||
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.toLowerCase() === feeRecipient.toLowerCase()) { | ||
fees.add(FEE_MAPPING[i], Number(log.value)); | ||
} | ||
}) | ||
}) | ||
|
||
return { | ||
dailyFees: fees, | ||
dailyRevenue: 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; |