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

Fix getCollaterals and getCollateralValue #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 1 addition & 10 deletions src/facade/borrow/borrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,11 @@ export class Borrow {
async getCollateralValue(
getCollateralValueOption: BorrowQueriesOptions,
): Promise<string> {
// only bLuna is supported now, and the below requests are only about bLuna
const oraclePrice = await queryOraclePrices({ lcd: this._lcd, limit: 30 })(
this._addressProvider,
);
const collaterals = await this.getCollaterals(getCollateralValueOption);

if (collaterals.length === 1 && collaterals[0] === null) {
return new Dec(0).toString();
}
Copy link
Contributor Author

@rramsden rramsden Aug 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be safely removed if the null return is removed, see other comment


const total = collaterals.reduce((sum, collateral) => {
const collateralPrice = oraclePrice.prices.find(
(p) => p.asset === collateral.collateral,
Expand Down Expand Up @@ -126,13 +121,9 @@ export class Borrow {
const userBalance = await queryCustodyBorrower({
lcd: this._lcd,
...getCollateralsOption,
custody: getCollateralsOption.market,
custody: whitelist.custody_contract,
})(this._addressProvider);

if (userBalance.balance === '0') {
return null;
}
Copy link
Contributor Author

@rramsden rramsden Aug 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a balance check here which returns null. It's a bit weird since if this condition is met you get something like the following back when this function is called:

[ null ]

Better to just return an actual entry e.g.

[
  {
    collateral: 'terra1....',
    balance: '0.000000000000000000'
  },
  {
    collateral: 'terra1....',
    balance: '0.000000000000000000'
  }
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just my opinion but this was added to make these functions work properly again


return {
collateral: whitelist.collateral_token,
balance: new Dec(userBalance.balance).toString(),
Expand Down