This repository was archived by the owner on Jan 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
[WIP] Brian/auction set up logic #181
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6fcfb86
Added logic to create token and unit arrays for bidding calcs. Added …
bweick 572281f
Integrating RebalancingTokenFactory to tests.
bweick f34d327
Pre-rebase commit (#185)
felix2feng ed95a4c
Finish renaming
felix2feng f1ee0af
Tests fixed using CoreMock.
bweick 54a67e0
Removing unused var.
bweick fd37b35
Minor renaming fixes in tests. Changed loop counter from uint16 -> ui…
bweick 0f73195
Rebalancing tests refactor. Moved common functions into RebalancingTo…
bweick 27152ef
Added getters for arrays created during propose. Revised tests to gen…
bweick 49a1a2a
Renamed constants and gave new values. Changed helper function names.…
bweick aa3933e
Small fix to make sure no block time error.
bweick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,11 @@ pragma solidity 0.4.24; | |
| import { DetailedERC20 } from "zeppelin-solidity/contracts/token/ERC20/DetailedERC20.sol"; | ||
| import { SafeMath } from "zeppelin-solidity/contracts/math/SafeMath.sol"; | ||
| import { StandardToken } from "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol"; | ||
| import { Bytes32 } from "../lib/Bytes32.sol"; | ||
| import { ICore } from "./interfaces/ICore.sol"; | ||
| import { ISetFactory } from "./interfaces/ISetFactory.sol"; | ||
| import { Bytes32 } from "../lib/Bytes32.sol"; | ||
| import { ISetToken } from "./interfaces/ISetToken.sol"; | ||
| import { AddressArrayUtils } from "../external/cryptofin/AddressArrayUtils.sol"; | ||
|
|
||
|
|
||
| /** | ||
|
|
@@ -35,6 +38,7 @@ contract RebalancingSetToken is | |
| { | ||
| using SafeMath for uint256; | ||
| using Bytes32 for bytes32; | ||
| using AddressArrayUtils for address[]; | ||
|
|
||
| /* ============ Enums ============ */ | ||
|
|
||
|
|
@@ -162,6 +166,7 @@ contract RebalancingSetToken is | |
| ) | ||
| external | ||
| { | ||
|
|
||
| // Make sure it is manager that is proposing the rebalance | ||
| require(msg.sender == manager); | ||
|
|
||
|
|
@@ -178,6 +183,9 @@ contract RebalancingSetToken is | |
| auctionStartPrice = _auctionStartPrice; | ||
| auctionPriceDivisor = _auctionPriceDivisor; | ||
|
|
||
| // Create token arrays needed for auction | ||
| parseUnitArrays(); | ||
|
|
||
| // Update state parameters | ||
| proposalStartTime = block.timestamp; | ||
| rebalanceState = State.Proposal; | ||
|
|
@@ -202,6 +210,12 @@ contract RebalancingSetToken is | |
| // Be sure the full proposal period has elapsed | ||
| require(block.timestamp >= proposalStartTime.add(proposalPeriod)); | ||
|
|
||
| // Get core address | ||
| address core = ISetFactory(factory).core(); | ||
|
|
||
| // Redeem current set held by rebalancing token in vault | ||
| ICore(core).redeemInVault(currentSet, unitShares.mul(totalSupply_)); | ||
|
|
||
| // Update state parameters | ||
| auctionStartTime = block.timestamp; | ||
| rebalanceState = State.Rebalance; | ||
|
|
@@ -331,6 +345,45 @@ contract RebalancingSetToken is | |
| return [unitShares]; | ||
| } | ||
|
|
||
| /* | ||
| * Get combinedTokenArray of Rebalancing Set | ||
| * | ||
| * @return combinedTokenArray | ||
| */ | ||
| function getCombinedTokenArray() | ||
| external | ||
| view | ||
| returns(address[]) | ||
| { | ||
| return combinedTokenArray; | ||
| } | ||
|
|
||
| /* | ||
| * Get combinedCurrentUnits of Rebalancing Set | ||
| * | ||
| * @return combinedCurrentUnits | ||
| */ | ||
| function getCombinedCurrentUnits() | ||
| external | ||
| view | ||
| returns(uint256[]) | ||
| { | ||
| return combinedCurrentUnits; | ||
| } | ||
|
|
||
| /* | ||
| * Get combinedRebalanceUnits of Rebalancing Set | ||
| * | ||
| * @return combinedRebalanceUnits | ||
| */ | ||
| function getCombinedRebalanceUnits() | ||
| external | ||
| view | ||
| returns(uint256[]) | ||
| { | ||
| return combinedRebalanceUnits; | ||
| } | ||
|
|
||
| /* ============ Transfer Overrides ============ */ | ||
|
|
||
| /* | ||
|
|
@@ -376,4 +429,67 @@ contract RebalancingSetToken is | |
| // Use inherited transferFrom function | ||
| return super.transferFrom(_from, _to, _value); | ||
| } | ||
|
|
||
| /* ============ Internal Functions ============ */ | ||
| function parseUnitArrays() | ||
| internal | ||
| { | ||
| // Create interfaces for interacting with sets | ||
| ISetToken currentSetInterface = ISetToken(currentSet); | ||
| ISetToken rebalancingSetInterface = ISetToken(rebalancingSet); | ||
|
|
||
| // Create combined token Array | ||
| address[] memory oldComponents = currentSetInterface.getComponents(); | ||
| address[] memory newComponents = rebalancingSetInterface.getComponents(); | ||
| combinedTokenArray = oldComponents.union(newComponents); | ||
|
|
||
| // Get naturalUnit of both sets | ||
| uint256 currentSetNaturalUnit = currentSetInterface.naturalUnit(); | ||
| uint256 rebalancingSetNaturalUnit = rebalancingSetInterface.naturalUnit(); | ||
|
|
||
| // Get units arrays for both sets | ||
| uint256[] memory currentSetUnits = currentSetInterface.getUnits(); | ||
| uint256[] memory rebalancingSetUnits = rebalancingSetInterface.getUnits(); | ||
|
|
||
| for (uint256 i=0; i < combinedTokenArray.length; i++) { | ||
| // Check if component in arrays and get index if it is | ||
| (uint256 indexCurrent, bool isInCurrent) = oldComponents.indexOf(combinedTokenArray[i]); | ||
| (uint256 indexRebalance, bool isInRebalance) = newComponents.indexOf(combinedTokenArray[i]); | ||
|
|
||
| // Compute and push unit amounts of token in currentSet, push 0 if not in set | ||
| if (isInCurrent) { | ||
| combinedCurrentUnits.push( | ||
| computeUnits(currentSetUnits[indexCurrent], currentSetNaturalUnit) | ||
| ); | ||
| } else { | ||
| combinedCurrentUnits.push(uint256(0)); | ||
| } | ||
|
|
||
| // Compute and push unit amounts of token in rebalancingSet, push 0 if not in set | ||
| if (isInRebalance) { | ||
| combinedRebalanceUnits.push( | ||
| computeUnits(rebalancingSetUnits[indexRebalance], rebalancingSetNaturalUnit) | ||
| ); | ||
| } else { | ||
| combinedRebalanceUnits.push(uint256(0)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Function to calculate the transfer value of a component given 1 Set | ||
| * | ||
| * @param _unit The units of the component token | ||
| * @param _naturalUnit The natural unit of the Set token | ||
| */ | ||
| function computeUnits( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have one of these functions elsewhere? If so, maybe we can avoid duplication by using a lib There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have something similar in Core but don't see a need to have us make a call to it in order to calculate this. |
||
| uint256 _unit, | ||
| uint256 _naturalUnit | ||
| ) | ||
| internal | ||
| returns (uint256) | ||
| { | ||
| uint256 coefficient = uint256(10) ** uint256(18); | ||
| return coefficient.mul(_unit).div(_naturalUnit); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| pragma solidity 0.4.24; | ||
|
|
||
| import { Core } from "../../core/Core.sol"; | ||
| import { ISetToken } from "../../core/interfaces/ISetToken.sol"; | ||
|
|
||
| // Mock contract implementation of Core with extra functions for testing | ||
| contract CoreMock is Core { | ||
| constructor( | ||
| address _transferProxy, | ||
| address _vault | ||
| ) | ||
| public | ||
| Core(_transferProxy, _vault) | ||
| {} | ||
|
|
||
| /* | ||
| * Mint set token for given address. | ||
| * Can only be called by authorized contracts. | ||
| * | ||
| * @param _set The address of the Set to mint | ||
| * @param _issuer The address of the issuing account | ||
| * @param _quantity The number of sets to attribute to issuer | ||
| */ | ||
| function mint( | ||
| address _set, | ||
| address _issuer, | ||
| uint256 _quantity | ||
| ) | ||
| external | ||
| { | ||
| ISetToken setToken = ISetToken(_set); | ||
|
|
||
| // Issue set token | ||
| setToken.mint( | ||
| _issuer, | ||
| _quantity | ||
| ); | ||
| } | ||
|
|
||
| /* | ||
| * Burn set token for given address. | ||
| * Can only be called by authorized contracts. | ||
| * | ||
| * @param _set The address of the Set to burn | ||
| * @param _from The address of the redeeming account | ||
| * @param _quantity The number of sets to burn from redeemer | ||
| */ | ||
| function burn( | ||
| address _set, | ||
| address _from, | ||
| uint256 _quantity | ||
| ) | ||
| external | ||
| { | ||
| ISetToken setToken = ISetToken(_set); | ||
|
|
||
| // Issue set token | ||
| setToken.burn( | ||
| _from, | ||
| _quantity | ||
| ); | ||
| } | ||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
interesting, do you have to cast this here?
uint256(0)?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.
Prob not but feel like we've fallen on the standard of explicitly stating what all the uints are