-
Notifications
You must be signed in to change notification settings - Fork 229
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
Conversation
67fe9df
to
7e1e932
Compare
There was a problem hiding this 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.
packages/ERTP/src/issuerKit.js
Outdated
* 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* `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.
packages/ERTP/src/issuerKit.js
Outdated
* @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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* 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 |
* @param {Amount<'nat'>} debtAmount | ||
* @param {Amount<'nat'>} collateralAmount |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
7e1e932
to
43255eb
Compare
chargeInterest
for use outside vaults
This makes sense, will do.
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 |
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. |
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 |
@Chris-Hibbert writes:
and @turadg took the commit with those changes out. So I suppose we're ready to go here. |
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.