Skip to content

Commit

Permalink
🐛 exactly: validate available pools (#1045)
Browse files Browse the repository at this point in the history
  • Loading branch information
itofarina authored Oct 20, 2023
1 parent 24d392c commit 41a2b19
Showing 1 changed file with 13 additions and 13 deletions.
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

0 comments on commit 41a2b19

Please sign in to comment.