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

add optional parameter to sumSingleBalance #89

Merged
merged 8 commits into from
Nov 24, 2022
Merged

Conversation

g1nt0ki
Copy link
Member

@g1nt0ki g1nt0ki commented Nov 18, 2022

Maybe balances[token] ?? 0 leads to unexpected behavior/bug as it would hide balance call failures where response is null|undefined

(balances[token] as number) = prevBalance + balance;
const value = prevBalance + balance
isValidNumber(value)
balances[token] = Number(value).toString()
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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

@g1nt0ki g1nt0ki merged commit 8a42648 into master Nov 24, 2022
@g1nt0ki g1nt0ki deleted the sumSingleBalance branch November 24, 2022 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants