From f0330d99af2280feac621d536bcbbea7fef034e6 Mon Sep 17 00:00:00 2001 From: Justin Chen Date: Sat, 23 Feb 2019 12:17:30 -0800 Subject: [PATCH] Handle other compile errors like explicit conversions between uint and byte, contract to address, and cleaning up DappHub code --- contracts/core/Vault.sol | 4 ++-- .../exchange-wrappers/KyberNetworkWrapper.sol | 4 ++-- .../core/interfaces/IExchangeIssueModule.sol | 6 ++--- .../core/interfaces/IRebalancingSetToken.sol | 4 ++-- contracts/core/interfaces/IVault.sol | 1 + .../core/lib/RebalancingHelperLibrary.sol | 2 ++ .../IAuctionPriceCurve.sol | 8 +++---- .../RebalancingTokenIssuanceModule.sol | 1 + .../tokens/RebalancingSetTokenFactory.sol | 24 ++++++++++--------- contracts/core/tokens/SetToken.sol | 3 ++- contracts/core/tokens/SetTokenFactory.sol | 16 +++++++------ .../StandardPlaceBidLibrary.sol | 1 + .../StandardSettleRebalanceLibrary.sol | 2 +- .../StandardStartRebalanceLibrary.sol | 2 +- contracts/external/DappHub/auth.sol | 4 ++-- contracts/external/DappHub/feed-factory.sol | 2 +- .../external/DappHub/interfaces/IMedian.sol | 4 ++-- contracts/external/DappHub/median.sol | 6 ++--- contracts/external/DappHub/note.sol | 7 +++++- contracts/external/DappHub/price-feed.sol | 4 ++-- contracts/lib/Bytes32.sol | 2 +- .../BTCETHRebalancingManager.sol | 5 ++-- package.json | 2 +- yarn.lock | 8 +++---- 24 files changed, 69 insertions(+), 53 deletions(-) diff --git a/contracts/core/Vault.sol b/contracts/core/Vault.sol index f325c5ccb..e21a196f6 100644 --- a/contracts/core/Vault.sol +++ b/contracts/core/Vault.sol @@ -74,7 +74,7 @@ contract Vault is // Retrieve current balance of token for the vault uint256 existingVaultBalance = ERC20Wrapper.balanceOf( _token, - this + address(this) ); // Call specified ERC20 token contract to transfer tokens from Vault to user @@ -87,7 +87,7 @@ contract Vault is // Verify transfer quantity is reflected in balance uint256 newVaultBalance = ERC20Wrapper.balanceOf( _token, - this + address(this) ); // Check to make sure current balances are as expected require( diff --git a/contracts/core/exchange-wrappers/KyberNetworkWrapper.sol b/contracts/core/exchange-wrappers/KyberNetworkWrapper.sol index 8f9d668a5..3d786a35a 100644 --- a/contracts/core/exchange-wrappers/KyberNetworkWrapper.sol +++ b/contracts/core/exchange-wrappers/KyberNetworkWrapper.sol @@ -199,7 +199,7 @@ contract KyberNetworkWrapper { address(this), destinationQuantityToTradeFor, trade.minimumConversionRate, - 0 + address(0) ); // Ensure the destination token is allowed to be transferred by Set TransferProxy @@ -265,7 +265,7 @@ contract KyberNetworkWrapper { private { // Transfer any unused or remainder maker token back to the issuance order user - uint256 remainderMakerToken = ERC20.balanceOf(_makerToken, this); + uint256 remainderMakerToken = ERC20.balanceOf(_makerToken, address(this)); if (remainderMakerToken > 0) { ERC20.transfer( _makerToken, diff --git a/contracts/core/interfaces/IExchangeIssueModule.sol b/contracts/core/interfaces/IExchangeIssueModule.sol index 4da8ef688..e0dc479d9 100644 --- a/contracts/core/interfaces/IExchangeIssueModule.sol +++ b/contracts/core/interfaces/IExchangeIssueModule.sol @@ -27,8 +27,8 @@ import { ExchangeIssueLibrary } from "../lib/ExchangeIssueLibrary.sol"; */ interface IExchangeIssueModule { function exchangeIssue( - ExchangeIssueLibrary.ExchangeIssueParams memory _exchangeIssueData, - bytes memory _orderData + ExchangeIssueLibrary.ExchangeIssueParams calldata _exchangeIssueData, + bytes calldata _orderData ) - public; + external; } diff --git a/contracts/core/interfaces/IRebalancingSetToken.sol b/contracts/core/interfaces/IRebalancingSetToken.sol index c942847ea..64421c365 100644 --- a/contracts/core/interfaces/IRebalancingSetToken.sol +++ b/contracts/core/interfaces/IRebalancingSetToken.sol @@ -78,7 +78,7 @@ interface IRebalancingSetToken { function balanceOf( address owner ) - public + external view returns (uint256); @@ -116,7 +116,7 @@ interface IRebalancingSetToken { * @return A address representing the base Set Token */ function currentSet() - public + external view returns (address); diff --git a/contracts/core/interfaces/IVault.sol b/contracts/core/interfaces/IVault.sol index a529af65b..e0d48c5e8 100644 --- a/contracts/core/interfaces/IVault.sol +++ b/contracts/core/interfaces/IVault.sol @@ -160,5 +160,6 @@ interface IVault { address _owner ) external + view returns (uint256); } diff --git a/contracts/core/lib/RebalancingHelperLibrary.sol b/contracts/core/lib/RebalancingHelperLibrary.sol index 4dfcfdc1b..503b95fc4 100644 --- a/contracts/core/lib/RebalancingHelperLibrary.sol +++ b/contracts/core/lib/RebalancingHelperLibrary.sol @@ -92,6 +92,7 @@ library RebalancingHelperLibrary { uint8 _rebalanceState ) public + view returns (uint256[] memory, uint256[] memory) { // Confirm in Rebalance State @@ -136,6 +137,7 @@ library RebalancingHelperLibrary { StandardStartRebalanceLibrary.BiddingParameters memory _biddingParameters ) public + pure returns (uint256[] memory, uint256[] memory) { // Declare unit arrays in memory diff --git a/contracts/core/lib/auction-price-libraries/IAuctionPriceCurve.sol b/contracts/core/lib/auction-price-libraries/IAuctionPriceCurve.sol index 41730fdde..61aac2332 100644 --- a/contracts/core/lib/auction-price-libraries/IAuctionPriceCurve.sol +++ b/contracts/core/lib/auction-price-libraries/IAuctionPriceCurve.sol @@ -42,9 +42,9 @@ interface IAuctionPriceCurve { * @param _auctionPriceParameters Struct containing relevant auction price parameters */ function validateAuctionPriceParameters( - RebalancingHelperLibrary.AuctionPriceParameters memory _auctionParameters + RebalancingHelperLibrary.AuctionPriceParameters calldata _auctionParameters ) - public + external view; /* @@ -55,9 +55,9 @@ interface IAuctionPriceCurve { * @return uint256 The auction price denominator */ function getCurrentPrice( - RebalancingHelperLibrary.AuctionPriceParameters memory _auctionParameters + RebalancingHelperLibrary.AuctionPriceParameters calldata _auctionParameters ) - public + external view returns (uint256, uint256); } diff --git a/contracts/core/modules/RebalancingTokenIssuanceModule.sol b/contracts/core/modules/RebalancingTokenIssuanceModule.sol index ee967223e..0617f158a 100644 --- a/contracts/core/modules/RebalancingTokenIssuanceModule.sol +++ b/contracts/core/modules/RebalancingTokenIssuanceModule.sol @@ -114,6 +114,7 @@ contract RebalancingTokenIssuanceModule is address _baseSetAddress ) private + view returns (uint256) { // Get Base Set Details from the rebalancing Set diff --git a/contracts/core/tokens/RebalancingSetTokenFactory.sol b/contracts/core/tokens/RebalancingSetTokenFactory.sol index a70b1434f..3803b7b7f 100644 --- a/contracts/core/tokens/RebalancingSetTokenFactory.sol +++ b/contracts/core/tokens/RebalancingSetTokenFactory.sol @@ -172,17 +172,19 @@ contract RebalancingSetTokenFactory { ); // Create a new SetToken contract - return new RebalancingSetToken( - this, - parameters.manager, - startingSet, - _units[0], - _naturalUnit, - parameters.proposalPeriod, - parameters.rebalanceInterval, - rebalanceComponentWhitelist, - _name.bytes32ToString(), - _symbol.bytes32ToString() + return address( + new RebalancingSetToken( + address(this), + parameters.manager, + startingSet, + _units[0], + _naturalUnit, + parameters.proposalPeriod, + parameters.rebalanceInterval, + rebalanceComponentWhitelist, + _name.bytes32ToString(), + _symbol.bytes32ToString() + ) ); } diff --git a/contracts/core/tokens/SetToken.sol b/contracts/core/tokens/SetToken.sol index 61041c79f..c6f9f650f 100644 --- a/contracts/core/tokens/SetToken.sol +++ b/contracts/core/tokens/SetToken.sol @@ -127,7 +127,8 @@ contract SetToken is // Figure out which of the components has the minimum decimal value /* solium-disable-next-line security/no-low-level-calls */ - if (currentComponent.call(bytes4(keccak256("decimals()")))) { + (bool success, ) = currentComponent.call(abi.encodeWithSignature("decimals()")); + if (success) { currentDecimals = ERC20Detailed(currentComponent).decimals(); minDecimals = currentDecimals < minDecimals ? currentDecimals : minDecimals; } else { diff --git a/contracts/core/tokens/SetTokenFactory.sol b/contracts/core/tokens/SetTokenFactory.sol index 791359b46..571d6f2e9 100644 --- a/contracts/core/tokens/SetTokenFactory.sol +++ b/contracts/core/tokens/SetTokenFactory.sol @@ -84,13 +84,15 @@ contract SetTokenFactory ); // Create a new SetToken contract - return new SetToken( - this, - _components, - _units, - _naturalUnit, - _name.bytes32ToString(), - _symbol.bytes32ToString() + return address( + new SetToken( + address(this), + _components, + _units, + _naturalUnit, + _name.bytes32ToString(), + _symbol.bytes32ToString() + ) ); } } diff --git a/contracts/core/tokens/rebalancing-libraries/StandardPlaceBidLibrary.sol b/contracts/core/tokens/rebalancing-libraries/StandardPlaceBidLibrary.sol index 587140588..9779374da 100644 --- a/contracts/core/tokens/rebalancing-libraries/StandardPlaceBidLibrary.sol +++ b/contracts/core/tokens/rebalancing-libraries/StandardPlaceBidLibrary.sol @@ -56,6 +56,7 @@ library StandardPlaceBidLibrary { uint8 _rebalanceState ) public + view returns (uint256[] memory, uint256[] memory) { // Make sure sender is a module diff --git a/contracts/core/tokens/rebalancing-libraries/StandardSettleRebalanceLibrary.sol b/contracts/core/tokens/rebalancing-libraries/StandardSettleRebalanceLibrary.sol index 507ef6302..60b5bfe19 100644 --- a/contracts/core/tokens/rebalancing-libraries/StandardSettleRebalanceLibrary.sol +++ b/contracts/core/tokens/rebalancing-libraries/StandardSettleRebalanceLibrary.sol @@ -198,7 +198,7 @@ library StandardSettleRebalanceLibrary { // Get amount of components in vault owned by rebalancingSetToken uint256 componentAmount = vaultInstance.getOwnerBalance( _setDetails.setComponents[i], - this + address(this) ); // Calculate amount of Sets that can be issued from those components, if less than amount for other diff --git a/contracts/core/tokens/rebalancing-libraries/StandardStartRebalanceLibrary.sol b/contracts/core/tokens/rebalancing-libraries/StandardStartRebalanceLibrary.sol index 9da4f07c3..77d2f5d49 100644 --- a/contracts/core/tokens/rebalancing-libraries/StandardStartRebalanceLibrary.sol +++ b/contracts/core/tokens/rebalancing-libraries/StandardStartRebalanceLibrary.sol @@ -317,7 +317,7 @@ library StandardStartRebalanceLibrary { // Get remainingCurrentSets and make it divisible by currentSet natural unit uint256 currentSetBalance = IVault(_vaultAddress).getOwnerBalance( _currentSet, - this + address(this) ); // Calculates the set's natural unit diff --git a/contracts/external/DappHub/auth.sol b/contracts/external/DappHub/auth.sol index 9135d082c..fa9ea2500 100644 --- a/contracts/external/DappHub/auth.sol +++ b/contracts/external/DappHub/auth.sol @@ -46,7 +46,7 @@ contract DSAuth is DSAuthEvents { auth { authority = authority_; - emit LogSetAuthority(authority); + emit LogSetAuthority(address(authority)); } modifier auth { @@ -62,7 +62,7 @@ contract DSAuth is DSAuthEvents { } else if (authority == DSAuthority(0)) { return false; } else { - return authority.canCall(src, this, sig); + return authority.canCall(src, address(this), sig); } } } diff --git a/contracts/external/DappHub/feed-factory.sol b/contracts/external/DappHub/feed-factory.sol index b8aa23381..1b43e8a9f 100644 --- a/contracts/external/DappHub/feed-factory.sol +++ b/contracts/external/DappHub/feed-factory.sol @@ -27,7 +27,7 @@ contract FeedFactory { PriceFeed feed = new PriceFeed(); emit Created(msg.sender, address(feed)); feed.setOwner(msg.sender); - isFeed[feed] = true; + isFeed[address(feed)] = true; return feed; } } diff --git a/contracts/external/DappHub/interfaces/IMedian.sol b/contracts/external/DappHub/interfaces/IMedian.sol index 1cdbcec02..fe971cef4 100644 --- a/contracts/external/DappHub/interfaces/IMedian.sol +++ b/contracts/external/DappHub/interfaces/IMedian.sol @@ -31,7 +31,7 @@ interface IMedian { * @return Current price of asset represented in hex as bytes32 */ function read() - public + external view returns (bytes32); @@ -41,7 +41,7 @@ interface IMedian { * @return Current price of asset represented in hex as bytes32, and whether value is non-zero */ function peek() - public + external view returns (bytes32, bool); } diff --git a/contracts/external/DappHub/median.sol b/contracts/external/DappHub/median.sol index 1ce621136..2a89b8aa1 100644 --- a/contracts/external/DappHub/median.sol +++ b/contracts/external/DappHub/median.sol @@ -34,11 +34,11 @@ contract Median is DSAuth { function read() public view returns (bytes32) { require(val > 0, "Invalid price feed"); - return bytes32(val); + return bytes32(uint256(val)); } function peek() public view returns (bytes32,bool) { - return (bytes32(val), val > 0); + return (bytes32(uint256(val)), val > 0); } function recover(uint256 val_, uint256 age_, uint8 v, bytes32 r, bytes32 s, bytes32 wat_) internal pure returns (address) { @@ -89,7 +89,7 @@ contract Median is DSAuth { } function lift(address a) public auth { - require(a != 0x0, "No oracle 0"); + require(a != address(0x0), "No oracle 0"); orcl[a] = true; } diff --git a/contracts/external/DappHub/note.sol b/contracts/external/DappHub/note.sol index bdae5224a..28b1a49db 100644 --- a/contracts/external/DappHub/note.sol +++ b/contracts/external/DappHub/note.sol @@ -34,8 +34,13 @@ contract DSNote { bar := calldataload(36) } - emit LogNote(msg.sig, msg.sender, foo, bar, msg.value, msg.data); + emit LogNote(msg.sig, msg.sender, foo, bar, getValue(), msg.data); _; } + + function getValue() internal view returns (uint256) + { + return msg.value; + } } diff --git a/contracts/external/DappHub/price-feed.sol b/contracts/external/DappHub/price-feed.sol index 0d96872de..70e20a2fc 100644 --- a/contracts/external/DappHub/price-feed.sol +++ b/contracts/external/DappHub/price-feed.sol @@ -30,13 +30,13 @@ contract PriceFeed is DSThing { function peek() external view returns (bytes32,bool) { - return (bytes32(val), now < zzz); + return (bytes32(uint256(val)), now < zzz); } function read() external view returns (bytes32) { require(now < zzz); - return bytes32(val); + return bytes32(uint256(val)); } function poke(uint128 val_, uint32 zzz_) external note auth diff --git a/contracts/lib/Bytes32.sol b/contracts/lib/Bytes32.sol index e794c8cd0..2a079ca14 100644 --- a/contracts/lib/Bytes32.sol +++ b/contracts/lib/Bytes32.sol @@ -24,7 +24,7 @@ library Bytes32 { returns (bytes memory) { uint256 i = 0; - while (i < 32 && uint256(data[i]) != 0) { + while (i < 32 && uint256(bytes32(data[i])) != 0) { ++i; } bytes memory result = new bytes(i); diff --git a/contracts/supplementary/rebalancing-manager/BTCETHRebalancingManager.sol b/contracts/supplementary/rebalancing-manager/BTCETHRebalancingManager.sol index c0cf94733..e28003070 100644 --- a/contracts/supplementary/rebalancing-manager/BTCETHRebalancingManager.sol +++ b/contracts/supplementary/rebalancing-manager/BTCETHRebalancingManager.sol @@ -361,6 +361,7 @@ contract BTCETHRebalancingManager { uint256 _ethPrice ) private + view returns (uint256, uint256, uint256[] memory) { // Initialize set token parameters @@ -461,7 +462,7 @@ contract BTCETHRebalancingManager { uint256[] memory _units ) private - view + pure returns (uint256) { // Calculate btcDollarAmount of one Set Token (in cents) @@ -500,7 +501,7 @@ contract BTCETHRebalancingManager { uint256 _tokenDecimals ) private - view + pure returns (uint256) { // Calculate the amount of component base units are in one full set token diff --git a/package.json b/package.json index 539ad83ee..a93c3a7f6 100644 --- a/package.json +++ b/package.json @@ -92,7 +92,7 @@ }, "dependencies": { "bn-chai": "^1.0.1", - "canonical-weth": "1.3.0", + "canonical-weth": "^1.3.1", "dotenv": "^6.2.0", "eth-gas-reporter": "^0.1.10", "expect": "^24.1.0", diff --git a/yarn.lock b/yarn.lock index b1c34ace2..0d38a408e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1698,10 +1698,10 @@ caniuse-lite@^1.0.30000844: resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000890.tgz#86a18ffcc65d79ec6a437e985761b8bf1c4efeaf" integrity sha512-4NI3s4Y6ROm+SgZN5sLUG4k7nVWQnedis3c/RWkynV5G6cHSY7+a8fwFyn2yoBDE3E6VswhTNNwR3PvzGqlTkg== -canonical-weth@1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/canonical-weth/-/canonical-weth-1.3.0.tgz#4e863fe55d63f3e33595a80b335731435bd2474f" - integrity sha512-q1FoFo8SH7FNhemgvvkeuhO7YzztRbEcBoetTlT4Djf83ExdZKo1Wzh1rca+ncjhO6A2J0Ehl/tVG6xUkVIJcg== +canonical-weth@^1.3.1: + version "1.3.1" + resolved "https://registry.yarnpkg.com/canonical-weth/-/canonical-weth-1.3.1.tgz#8c12172ee2cd63247c5f6c75be44a6b173b97fd1" + integrity sha512-sDVYcU4ta2ixs9NNmOS15i5sdNJqbAPx/l86rctEK0XcAKI/PEs0IKZ2GjJ2hgTabzf4LfwopgNIznNcS3aLSQ== caseless@~0.12.0: version "0.12.0"