Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Optimism, zkEVM pools to Idle adapter #1065

Merged
merged 6 commits into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/'
};
Loading