-
Notifications
You must be signed in to change notification settings - Fork 840
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Optimism, zkEVM pools to Idle adapter (#1065)
* NEW: added polygon pools * FIX: new line * FIX: Idle endpoint Authentication * NEW: idle optimism, zkevm pools * FIX: idle removed folder * NEW: idle dashboard url --------- Co-authored-by: Samster91 <samster91>
- Loading branch information
Showing
1 changed file
with
35 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,56 @@ | ||
const utils = require('../utils'); | ||
const superagent = require('superagent'); | ||
|
||
const AUTH_TOKEN_ENCODED = | ||
'ZXlKaGJHY2lPaUpJVXpJMU5pSXNJblI1Y0NJNklrcFhWQ0o5LmV5SmpiR2xsYm5SSlpDSTZJa0Z3Y0RZaUxDSnBZWFFpT2pFMk56QXlNemMxTWpkOS5rbnNtekVOSm40Yk5Ea0ZCM3h2eWZyaDBwVlFLTHY0NW9JanJQNHdRTU5N'; | ||
|
||
const mainnetPoolsUrl = 'https://api.idle.finance/pools'; | ||
// const polygonPoolsUrl = 'https://api-polygon.idle.finance/pools'; | ||
|
||
const chains = { | ||
eth: 'ethereum', | ||
// matic: 'polygon', | ||
ethereum: 'https://api.idle.finance/pools', | ||
polygon: 'https://api-polygon.idle.finance/pools', | ||
optimism: 'https://api-optimism.idle.finance/pools', | ||
polygon_zkevm: 'https://api-zkevm.idle.finance/pools', | ||
}; | ||
|
||
const AUTH_TOKEN_ENCODED = 'ZXlKaGJHY2lPaUpJVXpJMU5pSXNJblI1Y0NJNklrcFhWQ0o5LmV5SmpiR2xsYm5SSlpDSTZJa0Z3Y0RZaUxDSnBZWFFpT2pFMk56QXlNemMxTWpkOS5rbnNtekVOSm40Yk5Ea0ZCM3h2eWZyaDBwVlFLTHY0NW9JanJQNHdRTU5N'; | ||
|
||
async function getDataWithAuth(url, token) { | ||
const data = await superagent | ||
.get(url) | ||
.set('Authorization', `Bearer ${token}`); | ||
return data?.body; | ||
} | ||
|
||
async function apy() { | ||
const getApy = async () => { | ||
const AUTH_TOKEN_DECODED = atob(AUTH_TOKEN_ENCODED); | ||
const mainnetPoolsResponse = await getDataWithAuth( | ||
mainnetPoolsUrl, | ||
AUTH_TOKEN_DECODED | ||
const data = await Promise.all( | ||
Object.entries(chains).map(async (chain) => { | ||
const data = await getDataWithAuth(chain[1], AUTH_TOKEN_DECODED); | ||
return data.map((v) => { | ||
let protocolName = v.protocolName; | ||
if (v.borrowerName){ | ||
protocolName += ` ${v.borrowerName}` | ||
} | ||
return { | ||
pool: v.address, | ||
apyBase: Number(v.apr), | ||
symbol: v.tokenName, | ||
poolMeta: v.poolName.includes('Best') | ||
? v.poolName.split(' ').slice(1).join(' ') | ||
: `${protocolName} ${v.strategy}`, | ||
tvlUsd: Number(v.tvl), | ||
project: 'idle', | ||
chain: utils.formatChain(chain[0]), | ||
underlyingTokens: [v.underlyingAddress], | ||
} | ||
}); | ||
}) | ||
); | ||
|
||
// console.log('mainnetPoolsResponse', mainnetPoolsResponse) | ||
// const polygonPoolsResponse = await utils.getData(polygonPoolsUrl); | ||
|
||
const poolsResponse = { | ||
// matic: polygonPoolsResponse, | ||
eth: mainnetPoolsResponse, | ||
}; | ||
|
||
let allVaults = []; | ||
|
||
for (let chain of Object.keys(chains)) { | ||
const chainPools = Object.values(poolsResponse[chain]); | ||
|
||
const pools = chainPools.map((v) => ({ | ||
pool: v.address, | ||
apyBase: Number(v.apr), | ||
symbol: v.tokenName, | ||
poolMeta: v.poolName.includes('Best') | ||
? v.poolName.split(' ').slice(1).join(' ') | ||
: v.strategy, | ||
tvlUsd: Number(v.tvl), | ||
project: 'idle', | ||
chain: utils.formatChain(chains[chain]), | ||
underlyingTokens: [v.underlyingAddress], | ||
})); | ||
|
||
allVaults = [...allVaults, ...pools]; | ||
} | ||
|
||
return allVaults; | ||
} | ||
|
||
const main = async () => { | ||
return await apy(); | ||
return ( | ||
data | ||
.flat() | ||
); | ||
}; | ||
|
||
module.exports = { | ||
apy: main, | ||
timetravel: false, | ||
url: 'https://app.idle.finance/#/best', | ||
apy: getApy, | ||
url: 'https://app.idle.finance/' | ||
}; |