-
Notifications
You must be signed in to change notification settings - Fork 37
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
} | ||
|
||
const total = collaterals.reduce((sum, collateral) => { | ||
const collateralPrice = oraclePrice.prices.find( | ||
(p) => p.asset === collateral.collateral, | ||
|
@@ -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; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'
}
] There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(), | ||
|
There was a problem hiding this comment.
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