Skip to content

Conversation

jeanregisser
Copy link
Member

@jeanregisser jeanregisser commented Apr 14, 2023

All balances and prices are now required to be DecimalNumber or SerializedDecimalNumber.

  • DecimalNumber uses BigNumber under the hood, for arbitrary precision arithmetic.
  • SerializedDecimalNumber are stored as a strings with a maximum of 20 decimals. To avoid responses with too many decimals.

These were implemented using branded types. See https://michalzalecki.com/nominal-typing-in-typescript/.

The plugin interface has been updated to reflect this.

This should avoid confusion where previously balances could be in decimal format or as whole (large integer) numbers returned from ERC20 contracts.

An explicit call toDecimalNumber, toSerializedDecimalNumber or cast as DecimalNumber is needed, to satisfy the compiler. Making us think twice about what we are doing.

Let me know what you think.

Copy link
Contributor

@silasbw silasbw left a comment

Choose a reason for hiding this comment

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

nice

export function toDecimalNumber(value: BigNumber.Value): DecimalNumber
// Convert bigint balances from ERC20 contracts to decimal numbers
export function toDecimalNumber(value: bigint, decimals: number): DecimalNumber
export function toDecimalNumber(
Copy link
Contributor

Choose a reason for hiding this comment

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

I was kinda confused by the "cast" implementation because it's behavior is so different from the "shiftedBy" one. I think it would be slightly less confusing to drop the cast one and just us as directly.

@jeanregisser jeanregisser merged commit a8f920f into main Apr 24, 2023
@jeanregisser jeanregisser deleted the jeanregisser/use-big-number branch April 24, 2023 10:22
@github-actions
Copy link

🎉 This PR is included in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants