-
Notifications
You must be signed in to change notification settings - Fork 59
Add natural unit restrictions for proposed Set. Create minimumBid amo… #207
Conversation
Pull Request Test Coverage Report for Build 1895
💛 - Coveralls |
|
|
||
| pragma solidity 0.4.24; | ||
|
|
||
| import { AddressArrayUtils } from "../external/cryptofin/AddressArrayUtils.sol"; |
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.
FYI - If you rebase with master, this import now uses the CryptoFin import.
| * | ||
| * | ||
| * @param _rebalancingSet The Set to rebalance into | ||
| * @param _nextSet The Set to rebalance into |
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.
Knit: fix comment spacing
|
|
||
| for (uint256 i=0; i < combinedTokenArray.length; i++) { | ||
| uint256 rebalanceUnit = combinedRebalanceUnits[i]; | ||
| uint256 nextUnit = combinedNextUnits[i]; |
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.
Upon first glance, nextUnit seems like a confusing name. To be more discrete, maybe use something like nextSetUnit.
| * @return combinedNextUnits | ||
| */ | ||
| function getCombinedRebalanceUnits() | ||
| function getCombinedNextUnits() |
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.
Maybe getCombinedNextSetUnits
| * @return uint256 Amount of nextSets to issue | ||
| * @return uint256 New unitShares for the rebalancingSetToken | ||
| */ | ||
| function getIssueAmount() |
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.
We can name this better. It is currently too general and doesn't convey the work done. Perhaps something like calculateNextSetIssueQuantity.
02ef79f to
aae751d
Compare
| uint256 currentNaturalUnit = ISetToken(currentSet).naturalUnit(); | ||
| uint256 rebalancingNaturalUnit = ISetToken(_nextSet).naturalUnit(); | ||
| require( | ||
| Math.max256(currentNaturalUnit, rebalancingNaturalUnit) % |
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.
If we're going with nextSet, then the name of rebalancingNaturalUnit should be nextSetNaturalUnit or nextNaturalUnit
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.
Ah yes I agree...missed that one
| issueAmount | ||
| ); | ||
|
|
||
| // Ensure allowance to transfer sets to Vault |
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.
Don't need comment.
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.
Don't see the reason to be removing comments. They're free in my mind.
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.
If the code is clear enough, we don't need explanatory comments (which is a good thing). I'm not opinionated about this one. So up to you.
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 think above you talked about maintaining consistency and a long time ago we agreed on comments on every line and not assuming how obvious it is.
That being said, the comments could have a bit more color. In the case above, it could be, "Creating pointer to Core to Issue next set and Deposit into vault". This one could be: "Ensure transfer proxy has enough spender allowance to move issued nextSet to vault"
| // Create ICore object | ||
| ICore core = ICore(ISetFactory(factory).core()); | ||
|
|
||
| // Issue nextSet and deposit in Vault |
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.
This step doesn't deposit into the vault does it?
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.
+1
| issueAmount | ||
| ); | ||
|
|
||
| // Ensure allowance to transfer sets to Vault |
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 think above you talked about maintaining consistency and a long time ago we agreed on comments on every line and not assuming how obvious it is.
That being said, the comments could have a bit more color. In the case above, it could be, "Creating pointer to Core to Issue next set and Deposit into vault". This one could be: "Ensure transfer proxy has enough spender allowance to move issued nextSet to vault"
| // Create interfaces for interacting with sets | ||
| ISetToken currentSetInterface = ISetToken(currentSet); | ||
| ISetToken rebalancingSetInterface = ISetToken(rebalancingSet); | ||
| ISetToken nextSetInterface = ISetToken(nextSet); |
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.
Omit this interface suffix
| this | ||
| ); | ||
|
|
||
| // Calculate amount of Sets that can be issued from those components, if less than amount for other |
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.
Examples of great comments
| uint256 naturalUnitsOutstanding = totalSupply_.div(naturalUnit); | ||
|
|
||
| // Issue amount of Sets that is closest multiple of nextNaturalUnit to the maxIssueAmount | ||
| uint256 issueAmount = maxIssueAmount.div(nextNaturalUnit).mul(nextNaturalUnit); |
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.
Forgot, where does the dust that is not used to issue remain and who is the owner?
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.
Remains in the vault under the rebalancingSetToken's "ownership" so could be used in a future rebalance.
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.
who is ownership in this case? the manager? or they just belong to the reblanacing set token?
contracts/core/interfaces/ICore.sol
Outdated
| * Returns if valid set | ||
| * | ||
| * @return uint256 Natural unit of Set | ||
| * @return bool If valid set |
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.
Improve message here: "Returns whether set was...."
| it('transfers the full maker token amount from the maker', async () => { | ||
| const existingBalance = await makerToken.balanceOf.callAsync(issuanceOrderMaker); | ||
| await assertTokenBalance(makerToken, DEPLOYED_TOKEN_QUANTITY, issuanceOrderMaker); | ||
| await assertTokenBalanceAsync(makerToken, DEPLOYED_TOKEN_QUANTITY, issuanceOrderMaker); |
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.
Next time make these changes in a separate PR and rebase yours onto it
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.
Ignoring spec files unrelated to rebalancing
| const blockchain = new Blockchain(web3); | ||
|
|
||
|
|
||
|
|
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.
?
6b59da2 to
3fc00d4
Compare
| require(ICore(ISetFactory(factory).core()).validSets(_rebalancingSet)); | ||
| require(ICore(ISetFactory(factory).core()).validSets(_nextSet)); | ||
|
|
||
| // Check that the propoosed set is a multiple of current set, or vice versa |
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.
Knit: Check that the proposed Set natural unit is a multiple of current Set natural unit
utils/RebalancingTokenWrapper.ts
Outdated
| // Determine minimum natural unit if not passed in | ||
| if (naturalUnits) { | ||
| naturalUnit = naturalUnits[idx]; | ||
| minDec = 18 - naturalUnit.e; |
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.
What is .e?
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.
Exponent of the BigNumber
utils/RebalancingTokenWrapper.ts
Outdated
|
|
||
| const indexArray = _.times(tokenCount, Number); | ||
| for (const index in indexArray) { | ||
| let minDec: number; |
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.
Let's favor being verbose and descriptive in variable names.
minimumDecimal vs minDec
utils/RebalancingTokenWrapper.ts
Outdated
| for (const index in indexArray) { | ||
| let minDec: number; | ||
| const idx = Number(index); | ||
| const decOne = await components[idx].decimals.callAsync(); |
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.
Same here re: verbose
componentOneDecimal vs decOne
utils/RebalancingTokenWrapper.ts
Outdated
| const setComponents = components.slice(idx, idx + 2); | ||
| const setComponentAddresses = _.map(setComponents, token => token.address); | ||
| const setComponentUnits = _.map(setComponents, () => naturalUnit.mul(idx + 1)); // Multiple of naturalUnit | ||
| const setComponentUnits: BigNumber[] = |
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.
Improve formatting / readability by putting braces on their own lines
utils/RebalancingTokenWrapper.ts
Outdated
| const setComponentAddresses = _.map(setComponents, token => token.address); | ||
| const setComponentUnits = _.map(setComponents, () => naturalUnit.mul(idx + 1)); // Multiple of naturalUnit | ||
| const setComponentUnits: BigNumber[] = | ||
| [new BigNumber(10 ** (decOne.toNumber() - minDec)).mul(new BigNumber(idx + 1)), |
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.
Can we have simpler / intermediate calculations for component units?
…unt. Redo token flow math to use max component Set Token natural unit as base amount instead of 10**18. Figure out how many Sets to issue in settlement and recalcualte unitShares.
…ory then committed to storage. Added missing test for bid quantities that are not multiples of minimum bid.
241cef9 to
ec1c502
Compare
asoong
left a comment
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.
Some comments to address in future PRs, can you also rename RebalancingTokenWrapper.ts to rebalancingWrapper.ts
| nextUnit.mul(auctionPriceDivisor).sub(currentUnit.mul(priceNumerator)) | ||
| ).div(priceNumerator); | ||
|
|
||
| // Set outflow amount to 0 for component i |
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.
In subsequent PRs, improve comments here. "This bid price requires component i, so set outflow amount to 0". Sometimes we're too literal with our comments.
| currentUnit.mul(priceNumerator).sub(nextUnit.mul(auctionPriceDivisor)) | ||
| ).div(priceNumerator); | ||
|
|
||
| // Set inflow amount to 0 for component i |
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.
Same
| uint256 naturalUnitsOutstanding = totalSupply_.div(naturalUnit); | ||
|
|
||
| // Issue amount of Sets that is closest multiple of nextNaturalUnit to the maxIssueAmount | ||
| uint256 issueAmount = maxIssueAmount.div(nextNaturalUnit).mul(nextNaturalUnit); |
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.
who is ownership in this case? the manager? or they just belong to the reblanacing set token?
| }); | ||
|
|
||
| describe('but the proposed rebalancingSet is not approved by Core', async () => { | ||
| describe('but the proposed nextSet is not approved by Core', async () => { |
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.
but? update to when in subsequent pr
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 would look at it in the context of the whole statement being printed out "when propose is called from the Default state"..."but"
|
|
||
| describe("but the new proposed set's natural unit is not a multiple of the current set", async () => { | ||
| before(async () => { | ||
| naturalUnits = [ether(.003), ether(.002), ether(.001)]; |
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.
Add a comment to clarify these values. What is it being compared against that it is not a multiple of
…unt. Redo token flow math to use max component Set Token natural unit as base amount instead of 10**18. Figure out how many Sets to issue in settlement and recalcualte unitShares.