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

refactor!(zoe): handle subtracting empty in a less fragile way #3345

Merged
merged 4 commits into from
Jun 18, 2021

Conversation

katelynsills
Copy link
Contributor

@katelynsills katelynsills commented Jun 16, 2021

Closes #3335

#3184 required contracts to ensure that a keyword is specified before subtracting from the amount at that keyword. For instance:

const collectFees = seat => {
// Ensure that the feeSeat has a stagedAllocation with a RUN keyword
feeSeat.incrementBy({ RUN: AmountMath.makeEmpty(centralBrand) });
const amount = feeSeat.getAmountAllocated('RUN', centralBrand);
seat.incrementBy(feeSeat.decrementBy({ RUN: amount }));
zcf.reallocate(seat, feeSeat);

On second thought, this is way too fragile, and too much to require of contract developers.

This PR changes Zoe such that subtracting an empty amount, even from a keyword that does not exist, will not error. This will resolve the bug in #3335 in a way that handles the edge case for developers rather than requiring them to anticipate it.

@katelynsills katelynsills force-pushed the 3335-collect-fees-empty branch 2 times, most recently from 823347b to 648b352 Compare June 17, 2021 00:07
@katelynsills katelynsills self-assigned this Jun 17, 2021
@katelynsills
Copy link
Contributor Author

@michaelfig, added you as a backup reviewer in case @erights is too busy and we are having trouble getting it in by Monday.

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!

Comment on lines 58 to 59
amountToSubtract === undefined ||
(amountToSubtract !== undefined && AmountMath.isEmpty(amountToSubtract))
Copy link
Member

Choose a reason for hiding this comment

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

Is this just equivalent to:

Suggested change
amountToSubtract === undefined ||
(amountToSubtract !== undefined && AmountMath.isEmpty(amountToSubtract))
amountToSubtract === undefined || AmountMath.isEmpty(amountToSubtract)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is. I'll simplify :)

@katelynsills katelynsills enabled auto-merge (squash) June 18, 2021 17:35
@katelynsills katelynsills merged commit f51d327 into master Jun 18, 2021
@katelynsills katelynsills deleted the 3335-collect-fees-empty branch June 18, 2021 17:59
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.

Deducting empty from empty causes errors (treasury collectFees)
2 participants