Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.

Conversation

@bweick
Copy link
Contributor

@bweick bweick commented Sep 18, 2018

…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.

@coveralls
Copy link

coveralls commented Sep 18, 2018

Pull Request Test Coverage Report for Build 1895

  • 64 of 64 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.007%) to 99.858%

Totals Coverage Status
Change from base Build 1881: 0.007%
Covered Lines: 508
Relevant Lines: 508

💛 - Coveralls


pragma solidity 0.4.24;

import { AddressArrayUtils } from "../external/cryptofin/AddressArrayUtils.sol";
Copy link
Contributor

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
Copy link
Contributor

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];
Copy link
Contributor

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()
Copy link
Contributor

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()
Copy link
Contributor

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.

@bweick bweick force-pushed the brian/complete_rebalance_logic branch from 02ef79f to aae751d Compare September 23, 2018 17:12
uint256 currentNaturalUnit = ISetToken(currentSet).naturalUnit();
uint256 rebalancingNaturalUnit = ISetToken(_nextSet).naturalUnit();
require(
Math.max256(currentNaturalUnit, rebalancingNaturalUnit) %
Copy link
Contributor

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

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 yes I agree...missed that one

issueAmount
);

// Ensure allowance to transfer sets to Vault
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need comment.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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);
Copy link
Contributor

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
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

* Returns if valid set
*
* @return uint256 Natural unit of Set
* @return bool If valid set
Copy link
Contributor

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);
Copy link
Contributor

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

Copy link
Contributor

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);



Copy link
Contributor

Choose a reason for hiding this comment

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

?

@asoong asoong force-pushed the brian/complete_rebalance_logic branch from 6b59da2 to 3fc00d4 Compare September 26, 2018 19:33
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
Copy link
Contributor

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

// Determine minimum natural unit if not passed in
if (naturalUnits) {
naturalUnit = naturalUnits[idx];
minDec = 18 - naturalUnit.e;
Copy link
Contributor

Choose a reason for hiding this comment

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

What is .e?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exponent of the BigNumber


const indexArray = _.times(tokenCount, Number);
for (const index in indexArray) {
let minDec: number;
Copy link
Contributor

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

for (const index in indexArray) {
let minDec: number;
const idx = Number(index);
const decOne = await components[idx].decimals.callAsync();
Copy link
Contributor

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

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[] =
Copy link
Contributor

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

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)),
Copy link
Contributor

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?

bweick and others added 3 commits September 27, 2018 12:52
…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.
@bweick bweick force-pushed the brian/complete_rebalance_logic branch from 241cef9 to ec1c502 Compare September 27, 2018 19:52
Copy link
Contributor

@asoong asoong left a 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
Copy link
Contributor

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
Copy link
Contributor

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);
Copy link
Contributor

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 () => {
Copy link
Contributor

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

Copy link
Contributor Author

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)];
Copy link
Contributor

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

@bweick bweick merged commit c4d68b8 into master Sep 27, 2018
@bweick bweick deleted the brian/complete_rebalance_logic branch September 27, 2018 22:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants