@@ -6,72 +6,82 @@ const factoryAbi = require('./factory.abi.json');
66const axios = require ( 'axios' ) ;
77const { url } = require ( 'inspector' ) ;
88
9- const EULER_FACTORY = "0x29a56a1b8214D9Cf7c5561811750D5cBDb45CC8e" ;
10- const VAULT_LENS = "0x352e64E70bd1d2Fa46bDc2331D8220202c3f2c3B" ;
11- const EULER_DEPLOY_BLOCK = 20529225 ;
12-
9+ const chains = {
10+ ethereum : {
11+ factory : '0x29a56a1b8214D9Cf7c5561811750D5cBDb45CC8e' ,
12+ vaultLens : '0xA8695d44EC128136F8Afcd796D6ba3Db3cdA8914' ,
13+ fromBlock : 20529225 ,
14+ } ,
15+ bob : {
16+ factory : '0x046a9837A61d6b6263f54F4E27EE072bA4bdC7e4' ,
17+ vaultLens : '0xb20343277ad78150D21CC8820fF012efDDa71531' ,
18+ fromBlock : 12266832 ,
19+ } ,
20+ }
1321
1422const getApys = async ( ) => {
23+ const result = [ ] ;
24+
1525 const factoryIFace = new ethers . utils . Interface ( factoryAbi ) ;
1626 const lensIFace = new ethers . utils . Interface ( lensAbi ) ;
17- const currentBlock = await sdk . api . util . getLatestBlock ( 'ethereum' ) ;
18- const toBlock = currentBlock . number ;
19-
20- // Fetch all pools from factory events
21- const poolDeployEvents = await sdk . api . util . getLogs ( {
22- fromBlock : EULER_DEPLOY_BLOCK ,
23- toBlock : toBlock ,
24- target : EULER_FACTORY ,
25- chain : "ethereum" ,
26- topic : "" ,
27- keys : [ ] ,
28- topics : [ factoryIFace . getEventTopic ( 'ProxyCreated' ) ] ,
29- entireLog : true ,
30-
31- } ) ;
32-
33- const vaultAddresses = poolDeployEvents . output . map ( ( event ) => {
34- const decoded = factoryIFace . decodeEventLog ( "ProxyCreated" , event . data , event . topics ) ;
35- return decoded [ "proxy" ] ;
36- } ) ;
3727
28+ for ( const [ chain , config ] of Object . entries ( chains ) ) {
29+ const currentBlock = await sdk . api . util . getLatestBlock ( chain ) ;
30+ const toBlock = currentBlock . number ;
3831
39- const result = [ ] ;
40- // TODO loop over all vaults to get their info
41- for ( const vault of vaultAddresses ) {
42- const vaultInfo = await sdk . api . abi . call ( {
43- target : VAULT_LENS ,
44- params : [ vault ] ,
45- abi : lensAbi . find ( ( m ) => m . name === 'getVaultInfoFull' ) ,
46- chain : "ethereum" ,
32+ // Fetch all pools from factory events
33+ const poolDeployEvents = await sdk . api . util . getLogs ( {
34+ fromBlock : config . fromBlock ,
35+ toBlock : toBlock ,
36+ target : config . factory ,
37+ chain : chain ,
38+ topic : "" ,
39+ keys : [ ] ,
40+ topics : [ factoryIFace . getEventTopic ( 'ProxyCreated' ) ] ,
41+ entireLog : true ,
4742 } ) ;
4843
49- // Only pools with an interest rate
50- if ( vaultInfo . output . irmInfo . interestRateInfo [ 0 ] && vaultInfo . output . irmInfo . interestRateInfo [ 0 ] . supplyAPY > 0 ) {
44+ const vaultAddresses = poolDeployEvents . output . map ( ( event ) => {
45+ const decoded = factoryIFace . decodeEventLog ( "ProxyCreated" , event . data , event . topics ) ;
46+ return decoded [ "proxy" ] ;
47+ } ) ;
48+
49+ // TODO loop over all vaults to get their info
50+ for ( const vault of vaultAddresses ) {
51+ const vaultInfo = await sdk . api . abi . call ( {
52+ target : config . vaultLens ,
53+ params : [ vault ] ,
54+ abi : lensAbi . find ( ( m ) => m . name === 'getVaultInfoFull' ) ,
55+ chain,
56+ } ) ;
57+
58+ // Only pools with an interest rate
59+ if ( vaultInfo . output . irmInfo . interestRateInfo [ 0 ] && vaultInfo . output . irmInfo . interestRateInfo [ 0 ] . supplyAPY > 0 ) {
5160
52- const price = (
53- await axios . get ( `https://coins.llama.fi/prices/current/ethereum :${ vaultInfo . output . asset } ` )
54- ) . data . coins [ `ethereum :${ vaultInfo . output . asset } ` ] . price ;
61+ const price = (
62+ await axios . get ( `https://coins.llama.fi/prices/current/${ chain } :${ vaultInfo . output . asset } ` )
63+ ) . data . coins [ `${ chain } :${ vaultInfo . output . asset } ` ] . price ;
5564
56- const totalSupplied = vaultInfo . output . totalAssets ;
57- const totalBorrowed = vaultInfo . output . totalBorrowed ;
65+ const totalSupplied = vaultInfo . output . totalAssets ;
66+ const totalBorrowed = vaultInfo . output . totalBorrowed ;
5867
59- const totalSuppliedUSD = ethers . utils . formatUnits ( totalSupplied , vaultInfo . output . assetDecimals ) * price ;
60- const totalBorrowedUSD = ethers . utils . formatUnits ( totalBorrowed , vaultInfo . output . assetDecimals ) * price ;
68+ const totalSuppliedUSD = ethers . utils . formatUnits ( totalSupplied , vaultInfo . output . assetDecimals ) * price ;
69+ const totalBorrowedUSD = ethers . utils . formatUnits ( totalBorrowed , vaultInfo . output . assetDecimals ) * price ;
6170
62- result . push ( {
63- pool : vault ,
64- chain : "ethereum" ,
65- project : "euler-v2" ,
66- symbol : vaultInfo . output . vaultSymbol ,
67- tvlUsd : totalSuppliedUSD - totalBorrowedUSD ,
68- totalSupplyUsd : totalSuppliedUSD ,
69- totalBorrowUsd : totalBorrowedUSD ,
70- apyBase : Number ( ethers . utils . formatUnits ( vaultInfo . output . irmInfo . interestRateInfo [ 0 ] . supplyAPY , 25 ) ) ,
71- apyBaseBorrow : Number ( ethers . utils . formatUnits ( vaultInfo . output . irmInfo . interestRateInfo [ 0 ] . borrowAPY , 25 ) ) ,
72- underlyingTokens : [ vaultInfo . output . asset ] ,
73- url : `https://app.euler.finance/vault/${ vault } ` ,
74- } )
71+ result . push ( {
72+ pool : vault ,
73+ chain,
74+ project : "euler-v2" ,
75+ symbol : vaultInfo . output . vaultSymbol ,
76+ tvlUsd : totalSuppliedUSD - totalBorrowedUSD ,
77+ totalSupplyUsd : totalSuppliedUSD ,
78+ totalBorrowUsd : totalBorrowedUSD ,
79+ apyBase : Number ( ethers . utils . formatUnits ( vaultInfo . output . irmInfo . interestRateInfo [ 0 ] . supplyAPY , 25 ) ) ,
80+ apyBaseBorrow : Number ( ethers . utils . formatUnits ( vaultInfo . output . irmInfo . interestRateInfo [ 0 ] . borrowAPY , 25 ) ) ,
81+ underlyingTokens : [ vaultInfo . output . asset ] ,
82+ url : `https://app.euler.finance/vault/${ vault } ?network=${ chain } ` ,
83+ } )
84+ }
7585 }
7686 }
7787 return result ;
0 commit comments