-
Notifications
You must be signed in to change notification settings - Fork 100
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
add optional parameter to sumSingleBalance #89
Conversation
src/generalUtil.ts
Outdated
(balances[token] as number) = prevBalance + balance; | ||
const value = prevBalance + balance | ||
isValidNumber(value) | ||
balances[token] = Number(value).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.
why not keep it as number?
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.
hmm, this might have side effect when I think about it, if someone had mixed sumSingleBalance
and directly adding something to the balances object. like
sdk.util.sumSingleBalance(balances, 'tether', 500)
...
balances[tether] += 500
// would result in { tether: 500500 }
Maybe it is better to always convert it to a number? I dont strongly prefer number or string but thought it is better to stick to one type. Is there advantages using BigNumber
type?
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.
i think somewhere in defillama-server we might have some code that is based on checking whether a value is a number or not within balances, and this change would change all the values that used to be numbers into strings
not sure about this tho, but would be good to check
Maybe
balances[token] ?? 0
leads to unexpected behavior/bug as it would hide balance call failures where response isnull|undefined