@@ -3,13 +3,21 @@ const axios = require('axios');
33const utils = require ( '../utils' ) ;
44const ethers = require ( 'ethers' ) ;
55
6+ // RLP Constants
7+ const RLP = '0x4956b52aE2fF65D74CA2d61207523288e4528f96' ;
8+ const rlpPriceStorage = '0xaE2364579D6cB4Bbd6695846C1D595cA9AF3574d' ;
9+ const topic0priceSet =
10+ '0x2f0fe01aa6daff1c7bb411a324bdebe55dc2cd1e0ff2fc504b7569346e7d7d5a' ;
11+ const priceSetInterface = new ethers . utils . Interface ( [
12+ 'event PriceSet(bytes32 indexed key, uint256 price, uint256 timestamp);' ,
13+ ] ) ;
14+
15+ // stUSR Constants
616const stUSR = '0x6c8984bc7DBBeDAf4F6b2FD766f16eBB7d10AAb4' ;
717const USR = '0x66a1E37c9b0eAddca17d3662D6c05F4DECf3e110' ;
818const rewardDistributor = '0xbE23BB6D817C08E7EC4Cd0adB0E23156189c1bA9' ;
9-
1019const topic0rewardDistributed =
1120 '0x3863fc447b7dde3f3f5a5ca0b5b06a5fd3570963a1a29918f09036746293f658' ;
12-
1321const rewardDistributedInterface = new ethers . utils . Interface ( [
1422 'event RewardDistributed(bytes32 indexed idempotencyKey, uint256 totalShares, uint256 totalUSRBefore, uint256 totalUSRAfter, uint256 stakingReward, uint256 feeReward)' ,
1523] ) ;
@@ -50,6 +58,62 @@ const calculateStUSRApy = (logDescription) => {
5058 return ( ( sharesRateAfter - sharesRateBefore ) / sharesRateBefore ) * 365 ;
5159} ;
5260
61+ const rlpPool = async ( ) => {
62+ try {
63+ const totalSupply = await getTotalSupply ( RLP ) ;
64+ const currentBlock = await sdk . api . util . getLatestBlock ( 'ethereum' ) ;
65+ const currentDate = new Date ( currentBlock . timestamp * 1000 ) ;
66+ const previousStartOfDay =
67+ new Date ( currentDate ) . setHours ( 0 , 0 , 0 , 0 ) - 2 * DAY_IN_MS ;
68+
69+ const [ fromBlock ] = await utils . getBlocksByTime (
70+ [ previousStartOfDay / 1000 ] ,
71+ 'ethereum'
72+ ) ;
73+ const toBlock = currentBlock . block ;
74+
75+ const logs = (
76+ await sdk . api . util . getLogs ( {
77+ target : rlpPriceStorage ,
78+ topic : '' ,
79+ fromBlock,
80+ toBlock,
81+ keys : [ ] ,
82+ chain : 'ethereum' ,
83+ topics : [ topic0priceSet ] ,
84+ } )
85+ ) . output . sort ( ( a , b ) => a . blockNumber - b . blockNumber ) ;
86+
87+ let aprBase = 0 ;
88+ if ( logs . length >= 2 ) {
89+ const lastLpPrice = priceSetInterface . parseLog ( logs [ logs . length - 1 ] ) . args
90+ . price ;
91+ const previousLpPrice = priceSetInterface . parseLog ( logs [ logs . length - 2 ] )
92+ . args . price ;
93+
94+ aprBase = ( ( lastLpPrice - previousLpPrice ) / previousLpPrice ) * 365 ;
95+ }
96+
97+ const price =
98+ logs . length > 0
99+ ? priceSetInterface . parseLog ( logs [ logs . length - 1 ] ) . args . price / 1e18
100+ : await getTokenPrice ( RLP ) ;
101+ const tvl = totalSupply * price ;
102+
103+ return {
104+ pool : RLP ,
105+ symbol : 'RLP' ,
106+ chain : 'ethereum' ,
107+ project : 'resolv' ,
108+ tvlUsd : tvl ,
109+ apyBase : aprBase * 100 ,
110+ } ;
111+ } catch ( error ) {
112+ console . error ( 'Error fetching RLP pool data:' , error ) ;
113+ throw error ;
114+ }
115+ } ;
116+
53117const stUsrPool = async ( ) => {
54118 try {
55119 const totalSupply = await getTotalSupply ( stUSR ) ;
@@ -91,7 +155,7 @@ const stUsrPool = async () => {
91155 pool : stUSR ,
92156 symbol : 'stUSR' ,
93157 chain : 'ethereum' ,
94- project : 'resolv-usr ' ,
158+ project : 'resolv' ,
95159 tvlUsd : tvl ,
96160 apyBase : aprBase * 100 ,
97161 } ;
@@ -103,7 +167,7 @@ const stUsrPool = async () => {
103167
104168const apy = async ( ) => {
105169 try {
106- return [ await stUsrPool ( ) ] ;
170+ return [ await rlpPool ( ) , await stUsrPool ( ) ] ;
107171 } catch ( error ) {
108172 console . error ( 'Error fetching APYs:' , error ) ;
109173 throw error ;
0 commit comments