Skip to content

Commit

Permalink
Added Optimism, zkEVM pools to Idle adapter (#1065)
Browse files Browse the repository at this point in the history
* 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
samster91 authored Nov 6, 2023
1 parent 61a746b commit aeb7969
Showing 1 changed file with 35 additions and 48 deletions.
83 changes: 35 additions & 48 deletions src/adaptors/idle/index.js
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/'
};

0 comments on commit aeb7969

Please sign in to comment.