-
Notifications
You must be signed in to change notification settings - Fork 38
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?
Fix getCollaterals and getCollateralValue #30
Conversation
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
})(this._addressProvider); | ||
|
||
if (userBalance.balance === '0') { | ||
return null; | ||
} |
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.
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 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
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(); | ||
} |
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
Context
I noticed since bETH was introduced Borrow class
getCollaterals
andgetCollateralValue
no longer function.A case statement was introduced which broke functionality for
AddressFromJsonProvider
. Before this method just returned the custody contract address but now it can return a null value if the switch case oncollateral
doesn't match:anchor.js/src/address-provider/from-json.ts
Lines 64 to 73 in a4b3da7
For example, when Borrow calls
queryCustodyBorrower
the parametercustody
is passed with an instance ofMARKET_DENOMS
and not with the a collateral denomination:anchor.js/src/facade/borrow/borrow.ts
Lines 126 to 130 in a4b3da7
Then
custody
is type-casted to typeCOLLATERAL_DENOMS
and we just get a null value back from our switch caseanchor.js/src/queries/money-market/custody-borrower.ts
Lines 20 to 37 in a4b3da7
How to reproduce
You can see master branch no longer works running the following from node console: