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

🐛 exactly: validate available pools #1045

Merged
merged 1 commit into from
Oct 20, 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
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