1+ import { FetchOptions , SimpleAdapter } from "../adapters/types" ;
2+ import { CHAIN } from "../helpers/chains" ;
3+
4+ const CONTRACTS : Record < string , string > = {
5+ [ CHAIN . OPTIMISM ] : "0x7314af7d05e054e96c44d7923e68d66475ffaab8" ,
6+ [ CHAIN . ETHEREUM ] : "0xd1fdf0144be118c30a53e1d08cc1e61d600e508e" ,
7+ [ CHAIN . ARBITRUM ] : "0x02c282f60fb2f3299458c2b85eb7e303b25fc6f0" ,
8+ [ CHAIN . POLYGON ] : "0x03f490ae5b59e428e6692059d0dca1b87ed42ae1" ,
9+ } ;
10+
11+ const ProtoolFees = 'Protocol Fees'
12+ const KeepersFees = 'Keepers Fees'
13+
14+ const fetch = async ( options : FetchOptions ) => {
15+ const contract = CONTRACTS [ options . chain ] ;
16+ const dailyFees = options . createBalances ( ) ;
17+ const dailyProtocolRevenue = options . createBalances ( ) ;
18+ const dailySupplySideRevenue = options . createBalances ( ) ;
19+
20+ // Get KROM token address and protocol fee percentage
21+ const [ kromToken , protocolFeeRaw ] = await Promise . all ( [
22+ options . api . call ( { target : contract , abi : "function KROM() view returns (address)" } ) ,
23+ options . api . call ( { target : contract , abi : "function protocolFee() view returns (uint32)" } ) ,
24+ ] ) ;
25+
26+ // Fetch LimitOrderProcessed events to get service fees paid in KROM
27+ const logs = await options . getLogs ( {
28+ target : contract ,
29+ eventAbi : "event LimitOrderProcessed(address indexed monitor, uint256 indexed tokenId, uint256 serviceFeePaid)" ,
30+ } ) ;
31+
32+ const PROTOCOL_FEE_BASE = 100000n ;
33+ const protocolFee = BigInt ( protocolFeeRaw ) ;
34+
35+ logs . forEach ( ( log : any ) => {
36+ const serviceFee = BigInt ( log . serviceFeePaid || log [ 2 ] || 0 ) ;
37+ if ( serviceFee === 0n ) return ;
38+
39+ // Split: keepers gets base share, protocol gets remainder
40+ const keepersShare = serviceFee * PROTOCOL_FEE_BASE / ( PROTOCOL_FEE_BASE + protocolFee ) ;
41+ const protocolShare = serviceFee - keepersShare ;
42+
43+ dailyFees . add ( kromToken , protocolShare , ProtoolFees )
44+ dailyFees . add ( kromToken , keepersShare , KeepersFees )
45+
46+ dailyProtocolRevenue . add ( kromToken , protocolShare , ProtoolFees )
47+ dailySupplySideRevenue . add ( kromToken , keepersShare , KeepersFees )
48+ } ) ;
49+
50+ return {
51+ dailyFees,
52+ dailyUserFees : dailyFees ,
53+ dailyRevenue : dailyProtocolRevenue ,
54+ dailyProtocolRevenue,
55+ dailySupplySideRevenue,
56+ } ;
57+ } ;
58+
59+ const adapter : SimpleAdapter = {
60+ version : 2 ,
61+ adapter : {
62+ [ CHAIN . OPTIMISM ] : {
63+ fetch,
64+ start : "2022-08-01" ,
65+ } ,
66+ [ CHAIN . ETHEREUM ] : {
67+ fetch,
68+ start : "2022-01-01" ,
69+ } ,
70+ [ CHAIN . ARBITRUM ] : {
71+ fetch,
72+ start : "2022-08-01" ,
73+ } ,
74+ [ CHAIN . POLYGON ] : {
75+ fetch,
76+ start : "2022-08-01" ,
77+ } ,
78+ } ,
79+ methodology : {
80+ Volume : "Trading volume for limit orders processed by Kromatika." ,
81+ Fees : "Sum of KROM service fees emitted by LimitOrderManager when limit orders execute (LimitOrderProcessed events)." ,
82+ UserFees : 'Users pay fees for limit order while trading on Kromatika.' ,
83+ Revenue : "Portion of fees forwarded to the protocol fee address." ,
84+ ProtocolRevenue : "Service fees minus the monitor reimbursement share." ,
85+ SupplySideRevenue : "Share of service fees paid to execution monitors for covering gas costs." ,
86+ } ,
87+ breakdownMethodology :{
88+ Fees : {
89+ [ ProtoolFees ] : 'Service fees share to Kromatika,' ,
90+ [ KeepersFees ] : 'Service fees share to Chainlink Keepers,' ,
91+ } ,
92+ UserFees : {
93+ [ ProtoolFees ] : 'Service fees share to Kromatika,' ,
94+ [ KeepersFees ] : 'Service fees share to Chainlink Keepers,' ,
95+ } ,
96+ SupplySideRevenue : {
97+ [ KeepersFees ] : 'Service fees share to Chainlink Keepers,' ,
98+ } ,
99+ Revenue : {
100+ [ ProtoolFees ] : 'Service fees share to Kromatika,' ,
101+ } ,
102+ ProtocolRevenue : {
103+ [ ProtoolFees ] : 'Service fees share to Kromatika,' ,
104+ } ,
105+ } ,
106+ } ;
107+
108+ export default adapter ;
0 commit comments