Skip to content
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

changes to compile at 5.0 #100

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

7alexlin
Copy link

my attempt to make the zap-ethereum-api compile in solidity 5.0

require(curves[specifier] == 0, "Curve specifier already exists");
int256[] memory curve
) public returns(address) {
require(curves[specifier] == address(0) , "Curve specifier already exists");
Copy link
Author

Choose a reason for hiding this comment

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

require(curves[specifier] == 0) . could not compare and address to a uint, so casted address to zero with address(0)

contract Destructible is Ownable {
function selfDestruct() public onlyOwner {
selfdestruct(owner);
require(owner == msg.sender);
selfdestruct(msg.sender);
Copy link
Author

Choose a reason for hiding this comment

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

//was not compiling with selfdestruct(owner) added a require and changed parameter from owner to msg.sender

require(unbondAllow, "unbond not allowed");
super.unbond(msg.sender, gatewaySpecifier, quantity);
super.unbond1(msg.sender, gatewaySpecifier, quantity);
Copy link
Author

Choose a reason for hiding this comment

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

suspected namespacing issues so renamed function to unbond1 to prevent other bond function to be called correctly.

@@ -52,8 +52,8 @@ contract EthAdapter is ERCDotFactory {
}

//Override
function unbond(address wallet, bytes32 specifier, uint quantity) internal {

function unbond1(address payable wallet, bytes32 specifier, uint quantity) internal {
Copy link
Author

Choose a reason for hiding this comment

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

suspected namespacing issues so renamed function to unbond1 to prevent other bond function to be called correctly.

compiler kept throwing issue to unbond

@@ -66,10 +66,10 @@ contract EthAdapter is ERCDotFactory {
//burn dot backed token
tok.burnFrom(wallet, quantity);
//send wallet eth
wallet.transfer(reserveCost * adapterRate);
address(wallet).transfer(reserveCost * adapterRate);
Copy link
Author

Choose a reason for hiding this comment

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

compiler throwing issues to wallet.transfer

casted wallet to address(wallet) to avoid compiler error

@@ -44,23 +44,23 @@ contract EthGatedMarket is EthAdapter {
gatewaySpecifier = specifier;
setAdapterRate(adapterRate);
bondAllow = true;
return gatewayToken;
return address(gatewayToken);
Copy link
Author

Choose a reason for hiding this comment

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

compiler throwing error casted to address(gatewayToken) to fix compiler error

result += to_inc;
}
return address(result);
function bytesToAddr (bytes memory bys) public pure returns (address) {
Copy link
Author

Choose a reason for hiding this comment

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

old bytesToAddr function threw error at line 140 uint c = uint(b[i]);

could not cast bytes to uint

my work around was to find another algorithm online to caste bytes to address

@@ -61,7 +61,7 @@ contract FactoryToken is FactoryTokenInterface {

string public name;
string public symbol;
uint8 public decimals = 3;
uint8 public decimals = 18;
Copy link
Author

Choose a reason for hiding this comment

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

recheck to see if this is the proper decimal?

@@ -202,7 +202,7 @@ contract Bondage is Destructible, BondageInterface, Upgradable {
uint256 numZap = currentCost._costOfNDots(oracleAddress, endpoint, issued + 1, numDots - 1);

// User must have approved contract to transfer working ZAP
require(token.transferFrom(msg.sender, this, numZap), "Error: User must have approved contract to transfer ZAP");
require(token.transferFrom(msg.sender, address(this), numZap), "Error: User must have approved contract to transfer ZAP");
Copy link
Author

Choose a reason for hiding this comment

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

casted address(this) instead

function getEndpointBroker(address oracleAddress, bytes32 endpoint) public view returns (address) {
return address(db.getBytes32(keccak256(abi.encodePacked('oracles', oracleAddress, endpoint, 'broker'))));
function getEndpointBroker(address oracleAddress, bytes32 _endpoint) public payable returns (address) {
db.setBytes32(keccak256(abi.encodePacked('oracles', oracleAddress, _endpoint, 'broker')), _endpoint);
Copy link
Author

Choose a reason for hiding this comment

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

compiler was asking for 2 inputs when it only got 1.

changes i put was _endpoint for the second parameter and i let db.setbyte32 first before casting and returning. instead of returning in one time

db.setBytes32(keccak256(abi.encodePacked('oracles', msg.sender, endpoint, 'broker')), bytes32(broker));


db.setBytes32(keccak256(abi.encodePacked('oracles', msg.sender, endpoint, 'broker')), bytes32(uint256(broker) << 96));
Copy link
Author

Choose a reason for hiding this comment

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

compiler did not allow the casting of address to bytes32...

work around i found online was to cast the address to uint256 then to bytes32


emit NewCurve(msg.sender, endpoint, curve, broker);

return true;
}

function toBytes(address a) public pure returns (bytes memory) {
Copy link
Author

Choose a reason for hiding this comment

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

this can be removed.

originally was going to add this function to convert address to bytes1 but it was not necessary.

return db.getBytesArray(keccak256(abi.encodePacked('oracles', provider, 'endpointParams', endpoint)));
}

/// @dev get broker address for endpoint
function getEndpointBroker(address oracleAddress, bytes32 endpoint) public view returns (address) {
return address(db.getBytes32(keccak256(abi.encodePacked('oracles', oracleAddress, endpoint, 'broker'))));
db.getBytes32(keccak256(abi.encodePacked('oracles', oracleAddress, endpoint, 'broker')));
Copy link
Author

Choose a reason for hiding this comment

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

for some reason the original return with casting of db.getBytes32 on the return statement did not work.

had first let db.getBytes32 process then cast the return. by returning address(db)

Copy link
Author

@7alexlin 7alexlin left a comment

Choose a reason for hiding this comment

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

Most of these changes were to fill in the new syntax and semantics for compiling in solidity 5.0 which I had done successfully on my Terminal. Other major changes I made comments on for the reviewers to determine if it were the correct fix in comparison to the master branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant