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(run-protocol): extract chargeInterest for use outside vaults #4732

Merged
merged 7 commits into from
Mar 4, 2022

Conversation

turadg
Copy link
Member

@turadg turadg commented Mar 3, 2022

Description

getRUN will be charging interest like vaults do, so this pulls a chargeInterest function out. It has the added benefit of generalizing interest charging to any kind of NatValue brand.

Moves interest utils up to root of run-protocol since they're for more than just vaults now. Also does some validation that the brands match up.

Will merge as squash.

Security Considerations

No change in powers.

Documentation Considerations

--

Testing Considerations

CI sufficient.

@turadg turadg requested review from dckc and Chris-Hibbert March 3, 2022 22:42
@turadg turadg force-pushed the ta/getRun-support branch from 67fe9df to 7e1e932 Compare March 4, 2022 00:05
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.

I like the refactoring and relocation of interest calculation, though there's an associated piece that should be moved out of Zoe, I think.

On the changes to type declaration of Amounts, I'll have to defer to @erights

You have my LGTM once MarkM approves the ERTP type changes.

* from the mathHelpers library. For example, natMathHelpers, the
* default, is used for basic fungible tokens.
*
* `displayInfo` gives information to UI on how to display the amount.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* `displayInfo` gives information to UI on how to display the amount.
* `displayInfo` gives information to the UI on how to display the amount.

I realize you only moved these comments, but since I spotted typos, now seems the right time to fix them.

* @param {ShutdownWithFailure=} optShutdownWithFailure If this issuer fails
* in the middle of an atomic action (which btw should never happen), it
* potentially leaves its ledger in a corrupted state. If this function was
* provided, then it the failed atomic action will call it, so that some
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* provided, then it the failed atomic action will call it, so that some
* provided, then the failed atomic action will call it, so that some

Comment on lines 13 to 14
* @param {Amount<'nat'>} debtAmount
* @param {Amount<'nat'>} collateralAmount
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any chance we can make a constant or symbol to use here rather than a bare string? I realize this is a type declaration rather than javascript, so the answer may be "no", which would be unfortunate. If it only had to appear in our code that would be one thing, but if authors of contracts have to do this, I'm concerned about the opportunity for typos.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, tsc should grok a const NAT = 'nat'; thing, I'm told (and I've seen).

Whether it's smart enough for const { NAT } = AssetKind;, I don't know.

Copy link
Member Author

Choose a reason for hiding this comment

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

concerned about the opportunity for typos

The type parameter K must be a subtype of AssetKind which is the union of 'nat' | 'set' | 'copySet' | 'copyBag', so if someone were to type any string other than one of those four it would be a type failure. (type)

There may be an aesthetic argument to use AssetKind.NAT (const) but it would be more verbose without any safety benefit: Amount<AssetKind.NAT>.

Dan's Amount<NAT> idea would b no more verbose and a little cleaner but then you'd have to define or import NAT in the file you're typing that. (That import works, btw, because AssetKind object's type is a not [index]: string but literally each key to each value.)

Given how easy this would be to revert or change to either of the above, can we let it through and adjust as needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Second thought, this PR is unblocking and the types are just nice to have so I extracted to #4736

Copy link
Member

Choose a reason for hiding this comment

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

Given how easy this would be to revert or change to either of the above, can we let it through and adjust as needed?

I don't feel comfortable speaking for @erights on that.

@@ -27,10 +27,10 @@ const calculateRelativeCompounding = (

/**
*
* @param {Amount<NatValue>} debtSnapshot
* @param {Amount<'nat'>} debtSnapshot
Copy link
Contributor

Choose a reason for hiding this comment

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

All the methods in this file are only used within Vaults. Let's move it there for a start.

The follow-on question is whether it should be merged in with the new interest.js. I guess these only apply to the way that Vaults aggregate interest charges at the VaultManager level, so that would argue that it makes sense to leave them separate.

Would you mind moving it and adding comments about how special-purpose this is?

@turadg
Copy link
Member Author

turadg commented Mar 4, 2022

On the changes to type declaration of Amounts, I'll have to defer to @erights. You have my LGTM once MarkM approves the ERTP type changes.

Since that change is tangential to supporting getRUN I've pulled it off to #4736

@turadg turadg changed the title refactoring to support getRUN feature refactor(run-protocol): extract chargeInterest for use outside vaults Mar 4, 2022
@turadg turadg requested a review from Chris-Hibbert March 4, 2022 15:06
@turadg turadg marked this pull request as ready for review March 4, 2022 15:06
@turadg turadg added the automerge:squash Automatically squash merge label Mar 4, 2022
@turadg turadg marked this pull request as draft March 4, 2022 15:54
@turadg
Copy link
Member Author

turadg commented Mar 4, 2022

call it keyword rather than name.

This makes sense, will do.

I think we never use alleged names for anything other than debugging / display. I suggest making this an argument to chargeInterest.

Oh I wish this before I ran into the async lookup problem that required 27116fc. Is there no way to find out from a mint what keyword it expects in its mintGains method? I'll look in getIssuerRecord

@dckc
Copy link
Member

dckc commented Mar 4, 2022

... Is there no way to find out from a mint what keyword it expects in its mintGains method?

There's a misunderstand somewhere around here. Mints don't expect keywords. Zoe and contracts do. Keywords are part of the Zoe API, not the ERTP API.

@turadg
Copy link
Member Author

turadg commented Mar 4, 2022

Mints don't expect keywords

Maybe we're talking about different keywords? I'm referring to the AmountKeywordRecord type that mintGains of the mint expects.
Screen Shot 2022-03-04 at 11 04 44 AM

@Chris-Hibbert
Copy link
Contributor

the AmountKeywordRecord type that mintGains of the mint expects.

The mint/issuer doesn't constrain the type used there. That's a convention that the contract uses to coordinate between the seats. If the parts of your contract agree, you could call it Gains: or Foo:, and everyone would be happy.

@turadg turadg marked this pull request as ready for review March 4, 2022 20:18
@dckc
Copy link
Member

dckc commented Mar 4, 2022

@Chris-Hibbert writes:

You have my LGTM once MarkM approves the ERTP type changes.

and @turadg took the commit with those changes out. So I suppose we're ready to go here.

@mergify mergify bot merged commit 0c1a686 into master Mar 4, 2022
@mergify mergify bot deleted the ta/getRun-support branch March 4, 2022 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:squash Automatically squash merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants