Skip to content

Commit

Permalink
Merge branch 'DefiLlama:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAndrewClark authored Oct 23, 2023
2 parents 28b1227 + 41a2b19 commit 8173065
Show file tree
Hide file tree
Showing 47 changed files with 8,187 additions and 335 deletions.
67 changes: 67 additions & 0 deletions src/adaptors/circuit-protocol/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const utils = require('../utils');

const url = 'https://api.circuit.farm';
const urlApy = `${url}/apy`;
const urlTvl = `${url}/tvl`;
const urlMeta = `${url}/vaults`;

const networkMapping = {
5000: 'mantle',
}

const crctMapping = {
5000: '0x0000000000000000000000000000000000000000'
}


const main = async () => {
const [apy, tvl, meta] = await Promise.all(
[urlApy, urlTvl, urlMeta].map((u) => utils.getData(u))
);

let data = [];
for (const chain of Object.keys(networkMapping)) {
const poolData = tvl[chain];
for (const pool of Object.keys(poolData)) {
if (apy[pool] === undefined) {
continue;
}
const poolMeta = meta.find((m) => m?.id === pool);
const platformId = poolMeta?.platformId;

const poolId =
poolMeta === undefined
? crctMapping[chain]
: poolMeta.earnedTokenAddress;

const isActive = poolMeta === undefined || poolMeta.status == 'active';

if (!poolId) continue;

const underlyingTokens = (!!poolMeta && poolMeta.assets.length === 1 && poolMeta.tokenAddress) ? [poolMeta.tokenAddress] : undefined;

data.push({
pool: `${poolId}-${networkMapping[chain]}`.toLowerCase(),
chain: utils.formatChain(networkMapping[chain]),
project: 'circuit-protocol',
symbol:
poolMeta === undefined
? 'CRCT'
: utils.formatSymbol(poolMeta?.assets.join('-')),
tvlUsd: poolData[pool],
apy: isActive ? apy[pool] * 100 : 0,
poolMeta:
platformId === undefined ? null : utils.formatChain(platformId),
underlyingTokens,
});
}
}

return data;
};

module.exports = {
timetravel: false,
apy: main,
url: 'https://circuit.farm/',
};
26 changes: 13 additions & 13 deletions src/adaptors/exactly/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ const apy = async () =>
}

/** @type {Pool} */
const floating = {
const floating = Number.isFinite(apr) &&
Number.isFinite(borrowAPR) && {
...poolMetadata,
pool: `${market}-${chain}`.toLowerCase(),
apyBase: aprToApy(apr),
Expand Down Expand Up @@ -204,6 +205,15 @@ const apy = async () =>
fixSupplied = BigInt(supplied),
fixUnassignedEarnings = BigInt(unassignedEarnings);

if (fixSupplied + BigInt(previewFloatingAssetsAverages[i]) === 0n) return;

const { rate: minFixedRate } = await api2.abi.call({
target: interestRateModels[i],
abi: abis.minFixedRate,
params: [borrowed, supplied, previewFloatingAssetsAverages[i]],
block,
chain,
});
const unassignedEarning =
fixUnassignedEarnings -
(fixUnassignedEarnings * BigInt(timestampNow - lastAccrual)) /
Expand All @@ -220,16 +230,6 @@ const apy = async () =>
: 0;

const secsToMaturity = maturity - timestampNow;

const { rate: minFixedRate } = await api2.abi.call({
target: interestRateModels[i],
abi: abis.minFixedRate,
params: [borrowed, supplied, previewFloatingAssetsAverages[i]],
block,
chain,
});

const fixedBorrowAPR = previewFloatingAssetsAverages[i] + supplied > 0 ? minFixedRate / 1e16 : 0;
const poolMeta = new Date(maturity * 1_000).toISOString().slice(0, 10);

/** @type {Pool} */
Expand All @@ -238,7 +238,7 @@ const apy = async () =>
pool: `${market}-${chain}-${poolMeta}`.toLowerCase(),
poolMeta,
apyBase: aprToApy(fixedDepositAPR, secsToMaturity / 86_400),
apyBaseBorrow: aprToApy(fixedBorrowAPR, secsToMaturity / 86_400),
apyBaseBorrow: aprToApy(minFixedRate / 1e16, secsToMaturity / 86_400),
totalSupplyUsd:
(Number(
BigInt(supplied) +
Expand All @@ -254,7 +254,7 @@ const apy = async () =>
})
);

return [floating, ...fixed];
return [floating, ...fixed].filter(Boolean);
})
);
})
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const getApy = async () => {
return {
pool: p,
chain: utils.formatChain('avax'),
project: 'glacier-finance',
project: 'glacier-exchange-v2',
symbol: utils.formatSymbol(s.split('-')[1]),
tvlUsd,
apyReward,
Expand Down
4 changes: 0 additions & 4 deletions src/adaptors/gmx-v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ async function getPoolGlp(
apyReward: apyInflation,
rewardTokens:
chainString === 'arbitrum' ? [arbitrumGmxAddress] : [avalacheGmxAddress],

underlyingTokens: [
chainString === 'arbitrum' ? arbitrumGmxAddress : avalacheGmxAddress,
],
underlyingTokens: [
chainString === 'arbitrum'
? '0x4277f8F2c384827B5273592FF7CeBd9f2C1ac258'
Expand Down
Loading

0 comments on commit 8173065

Please sign in to comment.