1
+ import { FetchOptions , SimpleAdapter } from "../../adapters/types" ;
2
+ import { CHAIN } from "../../helpers/chains" ;
3
+
4
+ const MARKETS = {
5
+ [ CHAIN . ABSTRACT ] : '0x3e0F5F8F5Fb043aBFA475C0308417Bf72c463289' ,
6
+ [ CHAIN . LINEA ] : '0x39e66ee6b2ddaf4defded3038e0162180dbef340' ,
7
+ }
8
+
9
+ const abi = {
10
+ MarketActionTx : 'event MarketActionTx (address indexed user,uint8 indexed action, uint256 indexed marketId, uint256 outcomeId, uint256 shares, uint256 value, uint256 timestamp)' ,
11
+ getMarketAltData : 'function getMarketAltData(uint256 marketId) external view returns(uint256 buyFee, bytes32 questionId ,uint256 questionIdUint,address token,uint256 buyTreasuryFee, address treasury ,address realitio ,uint256 realitioTimeout ,address manager)' ,
12
+ getMarketFees : "function getMarketFees(uint256 marketId) view returns ((uint256 fee, uint256 treasuryFee, uint256 distributorFee) buyFees, (uint256 fee, uint256 treasuryFee, uint256 distributorFee) sellFees, address treasury, address distributor)" ,
13
+ }
14
+
15
+ async function fetch ( { createBalances, chain, api, getLogs } : FetchOptions ) {
16
+ const market = MARKETS [ chain ]
17
+ const dailyVolume = createBalances ( ) ;
18
+ const dailyFees = createBalances ( ) ;
19
+ const dailySupplySideRevenue = createBalances ( ) ;
20
+ const dailyRevenue = createBalances ( ) ;
21
+
22
+ const markets = await api . call ( { abi : 'uint256[]:getMarkets' , target : market } ) ;
23
+ const marketData = await api . multiCall ( { target : market , abi : abi . getMarketAltData , calls : markets } )
24
+ const marketFees = ( await api . multiCall ( { target : market , abi : abi . getMarketFees , calls : markets } ) )
25
+ const marketMapping : any = { }
26
+ markets . forEach ( ( val , idx ) => marketMapping [ val ] = {
27
+ token : marketData [ idx ] . token ,
28
+ fees : marketFees [ idx ]
29
+ } )
30
+
31
+ marketFees . forEach ( i => {
32
+ i . buyFees = i . buyFees . map ( j => Number ( j ) / 1e18 )
33
+ } )
34
+ const tradeLogs = await getLogs ( { target : market , eventAbi : abi . MarketActionTx , } ) ;
35
+
36
+ tradeLogs . forEach ( ( { action, marketId, value } ) => {
37
+ value = Number ( value )
38
+ action = Number ( action )
39
+ const { fees, token } = marketMapping [ marketId ]
40
+ const isBuy = action === 0
41
+ const feeKey = isBuy ? 'buyFees' : 'sellFees'
42
+ const [ fee , treasuryFee , distributorFee ] = fees [ feeKey ]
43
+ const totalFee = fee + treasuryFee + distributorFee
44
+
45
+ switch ( action ) {
46
+ case 0 : // buy
47
+ case 1 : // sell
48
+ dailyVolume . add ( token , value ) ;
49
+ dailyFees . add ( token , value * totalFee , isBuy ? 'BuyFee' : 'SellFee' )
50
+ dailySupplySideRevenue . add ( token , value * distributorFee , 'DistributorFee' )
51
+ dailySupplySideRevenue . add ( token , value * fee , 'LPFee' )
52
+ dailyRevenue . add ( token , value * fee , 'TreasuryFee' )
53
+ break ;
54
+ }
55
+ } ) ;
56
+
57
+
58
+ return {
59
+ dailyVolume,
60
+ dailyFees,
61
+ dailyRevenue,
62
+ dailyProtocolRevenue : dailyRevenue . clone ( ) ,
63
+ dailyHoldersRevenue : 0 ,
64
+ } ;
65
+ }
66
+
67
+ const methodology = {
68
+ Fees : "fees charged on buys/sells (usually 3%)" ,
69
+ Revenue : "1% fee to fund further development of Myriad Markets" ,
70
+ ProtocolRevenue : "All revenue go to the protocol" ,
71
+ SupplySideRevenue : "1% fee to reward liquidity providers & 1% fee to the distributors" ,
72
+ } ;
73
+
74
+ const breakdownMethodology = {
75
+ Fees : {
76
+ 'BuyFee' : 'Fee charged while buying' ,
77
+ 'SellFee' : 'Fee charged while selling' ,
78
+ } ,
79
+ Revenue : {
80
+ 'TreasuryFee' : 'Part of trading fee that goes to the protocol treasury' ,
81
+ } ,
82
+ SupplySideRevenue : {
83
+ 'DistributorFee' : 'Cut from trading fees to the distributors' ,
84
+ 'LPFee' : 'Cut from trading fees to the Liquidity providers' ,
85
+ } ,
86
+ }
87
+
88
+
89
+ const adapter : SimpleAdapter = {
90
+ version : 2 ,
91
+ fetch,
92
+ breakdownMethodology,
93
+ adapter : {
94
+ [ CHAIN . ABSTRACT ] : { start : '2025-07-06' , } ,
95
+ [ CHAIN . LINEA ] : { start : '2025-08-01' , } ,
96
+ } ,
97
+ methodology
98
+ } ;
99
+
100
+ export default adapter ;
0 commit comments