File tree 6 files changed +99
-5
lines changed 6 files changed +99
-5
lines changed Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ const getApys = async () => {
131
131
}
132
132
}
133
133
}
134
- return result ;
134
+ return utils . addMerklRewardApy ( result , 'euler' ) ;
135
135
} ;
136
136
137
137
module . exports = {
Original file line number Diff line number Diff line change @@ -388,11 +388,13 @@ const getApy = async () => {
388
388
'0x431f6e577a431d9ee87a535fde2db830e352e33c' ,
389
389
'0xed17209ab7f9224e29cc9894fa14a011f37b6115' ,
390
390
] ;
391
- return pools . flat ( ) . map ( ( i ) => ( {
391
+ const data = pools . flat ( ) . map ( ( i ) => ( {
392
392
...i ,
393
393
apyReward : x . includes ( i . pool ) || i . chain === 'Manta' ? null : i . apyReward ,
394
394
rewardTokens : x . includes ( i . pool ) || i . chain === 'Manta' ? null : i . rewardTokens ,
395
395
} ) ) . filter ( p => p . chain != 'Binance' ) ;
396
+
397
+ return utils . addMerklRewardApy ( data , 'gamma' , ( p ) => p . pool . split ( '-' ) [ 0 ] ) ;
396
398
} ;
397
399
398
400
module . exports = {
Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ const networks = {
9
9
1101 : 'polygon_zkevm' ,
10
10
8453 : 'base' ,
11
11
60808 : 'bob' ,
12
+ 146 : 'sonic' ,
13
+ 43114 : 'avax' ,
14
+ 80094 : 'berachain' ,
15
+ 56 : 'bsc' ,
12
16
} ;
13
17
14
18
// Protocols that should not be listed under Merkl
@@ -18,6 +22,7 @@ const protocolsBlacklist = [
18
22
'crosscurve' ,
19
23
'aerodrome' ,
20
24
'gamma' ,
25
+ 'uniswap' ,
21
26
] ;
22
27
23
28
// Allow specific pools from blacklisted protocols
@@ -50,6 +55,7 @@ const main = async () => {
50
55
data = await utils . getData ( `https://api.merkl.xyz/v4/opportunities?chainId=${ chainId } &status=LIVE&items=100&page=${ pageI } ` ) ;
51
56
} catch ( err ) {
52
57
console . log ( 'failed to fetch Merkl data on chain ' + chain ) ;
58
+ break ;
53
59
}
54
60
55
61
if ( data . length === 0 ) {
Original file line number Diff line number Diff line change @@ -126,7 +126,10 @@ const main = async (timestamp = null) => {
126
126
}
127
127
}
128
128
129
- return data . filter ( ( p ) => utils . keepFinite ( p ) ) ;
129
+ return utils . addMerklRewardApy (
130
+ data . filter ( ( p ) => utils . keepFinite ( p ) ) ,
131
+ 'uniswap'
132
+ ) ;
130
133
} ;
131
134
132
135
module . exports = {
Original file line number Diff line number Diff line change @@ -352,7 +352,8 @@ const main = async (timestamp = null) => {
352
352
) ;
353
353
}
354
354
data . push ( ...( await getOnchainPools ( ) ) )
355
- return data
355
+ return utils . addMerklRewardApy (
356
+ data
356
357
. flat ( )
357
358
. filter (
358
359
( p ) =>
@@ -361,7 +362,9 @@ const main = async (timestamp = null) => {
361
362
'0x0c6d9d0f82ed2e0b86c4d3e9a9febf95415d1b76' ,
362
363
'0xc809d13e9ea08f296d3b32d4c69d46ff90f73fd8' ,
363
364
] . includes ( p . pool )
364
- ) ;
365
+ ) ,
366
+ 'uniswap'
367
+ ) ;
365
368
} ;
366
369
367
370
module . exports = {
Original file line number Diff line number Diff line change @@ -513,3 +513,83 @@ exports.getTotalSupply = async (tokenMintAddress) => {
513
513
514
514
return supplyInTokens ;
515
515
} ;
516
+
517
+ const merklNetworks = {
518
+ 1 : 'ethereum' ,
519
+ 137 : 'polygon' ,
520
+ 10 : 'optimism' ,
521
+ 42161 : 'arbitrum' ,
522
+ 1101 : 'polygon_zkevm' ,
523
+ 8453 : 'base' ,
524
+ 60808 : 'bob' ,
525
+ 146 : 'sonic' ,
526
+ 43114 : 'avax' ,
527
+ 80094 : 'berachain' ,
528
+ 56 : 'bsc' ,
529
+ }
530
+
531
+ exports . addMerklRewardApy = async (
532
+ pools ,
533
+ protocolId ,
534
+ poolAddressGetter ,
535
+ ) => {
536
+ try {
537
+ let merklPools = [ ] ;
538
+ let pageI = 0 ;
539
+
540
+ while ( true ) {
541
+ let data ;
542
+ try {
543
+ data = await exports . getData ( `https://api.merkl.xyz/v4/opportunities?mainProtocolId=${ protocolId } &status=LIVE&items=100&page=${ pageI } ` ) ;
544
+ } catch ( err ) {
545
+ console . log ( `failed to fetch Merkl data for ${ protocolId } : ${ err } ` ) ;
546
+ break ;
547
+ }
548
+
549
+ if ( data . length === 0 ) {
550
+ break ;
551
+ }
552
+
553
+ merklPools . push ( ...data ) ;
554
+ pageI ++ ;
555
+ }
556
+
557
+
558
+ const merklPoolsMap = Object . fromEntries ( Object . keys ( merklNetworks ) . map ( id => [ merklNetworks [ id ] , { } ] ) ) ;
559
+ merklPools . forEach ( pool => {
560
+ if ( ! merklNetworks [ pool . chainId ] ) {
561
+ return ;
562
+ }
563
+
564
+ merklPoolsMap [ merklNetworks [ pool . chainId ] ] [ pool . identifier . toLowerCase ( ) ] = {
565
+ apyReward : pool . apr ,
566
+ rewardTokens : [ ...new Set ( pool . rewardsRecord ?. breakdowns . map ( x => x . token . address ) || [ ] ) ]
567
+ }
568
+ } ) ;
569
+
570
+ return pools . map ( pool => {
571
+ const poolAddress = poolAddressGetter ? poolAddressGetter ( pool ) : pool . pool ;
572
+ const merklRewards = merklPoolsMap [ pool . chain . toLowerCase ( ) ] [ poolAddress . toLowerCase ( ) ] ;
573
+
574
+ if ( ! merklRewards ) {
575
+ return pool ;
576
+ }
577
+
578
+ // if the data is already present, don't overwrite it
579
+ if ( pool . apyReward || ( pool . rewardTokens && pool . rewardTokens . length !== 0 ) ) {
580
+ console . log ( 'pool already has apyReward or rewardTokens' , pool . pool ) ;
581
+ return pool ;
582
+ }
583
+
584
+ return {
585
+ ...pool ,
586
+ ...merklRewards ,
587
+ }
588
+ } ) ;
589
+ } catch ( err ) {
590
+ console . log ( `Failed to add Merkl reward apy to ${ protocolId } : ${ err } ` ) ;
591
+
592
+ // If we fail to fetch Merkl data, just return the original pools
593
+ return pools ;
594
+ }
595
+ } ;
You can’t perform that action at this time.
0 commit comments