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

feat: add a decimals parameter, and decimals method to brand #1964

Merged
merged 7 commits into from
Nov 4, 2020

Conversation

katelynsills
Copy link
Contributor

@katelynsills katelynsills commented Nov 3, 2020

This PR adds a displayInfo object to an ERTP issuerKit, including a decimalPlaces property in the same way that Ethereum uses their decimals property. We intend for fungible digital assets to be represented as integers in the smallest unit. (In finance, this is often mills.) However, we want to display in a more user-friendly way. decimalPlaces is meant only for display, and informs the UI how many decimal places to move the decimal over to the left. For instance, for mills, one thousandth of a dollar, decimals would be 3.

The downside is that this hardcodes a certain interpretation. For instance, it would hard-code a dollar as the standard representation instead of millions or thousands of dollars. However, the UI is free to ignore decimals.

One upside is that compared to something like a custom toString, decimals is very safe. An attacker can't do much with the ability to choose an integer that will later be returned.

Closes #119

@katelynsills katelynsills added the ERTP package: ERTP label Nov 3, 2020
@katelynsills katelynsills self-assigned this Nov 3, 2020
Copy link
Member

@michaelfig michaelfig left a comment

Choose a reason for hiding this comment

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

LGTM!

The brand is a good place to put this information, in case amountMath is later sensitive to it.

packages/ERTP/src/issuer.js Outdated Show resolved Hide resolved
packages/ERTP/src/issuer.js Outdated Show resolved Hide resolved
@Chris-Hibbert Chris-Hibbert added the Zoe package: Zoe label Nov 3, 2020
Copy link
Contributor

@Chris-Hibbert Chris-Hibbert left a comment

Choose a reason for hiding this comment

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

The downside is that this hardcodes a certain interpretation.

I think the right way to think of this is that 'decimals' tells the display software which position corresponds to whole numbers. If the display wants to display Millions, then it knows that it should be millions of that unit, rather than millions of the most precise division.

if mills are the unit, and decimals is set to 3, then

  • 3000 is $3.00
  • 3 000 000 is $3000.00
  • 3 000 000 000 could be rendered $3.0M

packages/ERTP/src/issuer.js Outdated Show resolved Hide resolved
@katelynsills
Copy link
Contributor Author

Addressed PR comments. In order to ensure displayInfo is as expected, I copied over a few helpers from Zoe. Not happy about that, but I also don't want to create a package for two helpers before the hackathon.

Copy link
Member

@erights erights left a comment

Choose a reason for hiding this comment

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

Once the safety issue is addressed with the pureCopy, LGTM.

packages/ERTP/src/issuer.js Outdated Show resolved Hide resolved
* numbers. We require fungible digital assets to be represented in
* integers, in the smallest unit (i.e. USD might be represented in mill,
* a thousandth of a dollar. In that case, `decimalPlaces` would be 3.)
* For non-fungible digital assets, this should be left as undefined.
Copy link
Member

Choose a reason for hiding this comment

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

DisplayInfo should be expected to grow over time as one would expect of an options bag. Each use would only contain properties appropriate for the kind of amount math it is used on. Rather than having decimalPlaces be undefined, the property should be optional. AFAICT your assertDisplayInfo already allows it to be absent so it is just an issue of how you type and describe it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, yep, that is what I intended. Will change

packages/ERTP/src/types.js Show resolved Hide resolved
@katelynsills katelynsills requested a review from erights November 3, 2020 23:44
Copy link
Member

@erights erights left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -23,7 +23,7 @@ function makeIssuerKit(
displayInfo = undefined,
) {
assert.typeof(allegedName, 'string');
assertDisplayInfo(displayInfo);
displayInfo = coerceDisplayInfo(displayInfo);
Copy link
Member

Choose a reason for hiding this comment

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

Good you changed the assert into a coerce and let it do the coercion. Better than what I suggested.


export const coerceDisplayInfo = allegedDisplayInfo => {
if (passStyleOf(allegedDisplayInfo) === REMOTE_STYLE) {
return harden({});
Copy link
Member

Choose a reason for hiding this comment

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

This is too loose. Once you see it is a remotable, you should also assert that it is an empty object before returning a new empty object. Otherwise, an accidental passing of a substantive remotable object will silently become an empty object rather than rejected with a nice diagnostic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@erights How would you assert it is an empty object if it's a presence? I thought doing something like getting the ownPropertyNames wouldn't work.

Copy link
Member

Choose a reason for hiding this comment

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

See #1981

@michaelfig michaelfig merged commit 311dc41 into master Nov 4, 2020
@michaelfig michaelfig deleted the 119-decimal branch November 4, 2020 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ERTP package: ERTP Zoe package: Zoe
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ERTP] decimal property
4 participants