From 55898f28e389a81bc7dd92c82c02690e2ceda2f6 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 20 Jun 2019 13:21:35 -0400 Subject: [PATCH 1/2] changes to compile at 5.0 --- contracts/lib/ERC20.sol | 6 +- contracts/lib/lifecycle/Destructible.sol | 5 +- contracts/lib/ownership/Ownable.sol | 2 +- contracts/lib/ownership/Upgradable.sol | 2 +- contracts/lib/ownership/ZapCoordinator.sol | 10 +- .../lib/ownership/ZapCoordinatorInterface.sol | 10 +- contracts/lib/platform/BTCcontest.sol | 76 ----- contracts/lib/platform/Client.sol | 14 +- contracts/lib/platform/ERCDotFactory.sol | 18 +- contracts/lib/platform/EthAdapter.sol | 16 +- contracts/lib/platform/EthGatedMarket.sol | 28 +- .../lib/platform/MostBondedByDateContest.sol | 48 --- contracts/lib/platform/OnChainProvider.sol | 4 +- contracts/lib/platform/PiecewiseLogic.sol | 6 +- contracts/lib/platform/SampleContest.sol | 316 ------------------ .../lib/platform/SampleOnChainOracle.sol | 16 +- contracts/lib/platform/Telegram.sol | 4 +- contracts/lib/platform/TestContracts.sol | 24 +- contracts/lib/platform/TokenAdapter.sol | 6 +- contracts/lib/platform/TokenDotFactory.sol | 37 +- contracts/lib/token/FactoryTokenInterface.sol | 2 +- contracts/lib/token/Token.sol | 6 +- contracts/lib/token/TokenFactory.sol | 7 +- contracts/lib/token/TokenFactoryInterface.sol | 4 +- contracts/platform/arbiter/Arbiter.sol | 6 +- .../platform/arbiter/ArbiterInterface.sol | 6 +- contracts/platform/bondage/Bondage.sol | 11 +- .../platform/bondage/BondageInterface.sol | 2 +- .../bondage/currentCost/CurrentCost.sol | 2 +- .../currentCost/CurrentCostInterface.sol | 2 +- contracts/platform/database/Database.sol | 22 +- .../platform/database/DatabaseInterface.sol | 22 +- contracts/platform/dispatch/Dispatch.sol | 34 +- .../platform/dispatch/DispatchInterface.sol | 30 +- contracts/platform/registry/Registry.sol | 33 +- .../platform/registry/RegistryInterface.sol | 20 +- 36 files changed, 212 insertions(+), 645 deletions(-) mode change 100644 => 100755 contracts/lib/ERC20.sol mode change 100644 => 100755 contracts/lib/lifecycle/Destructible.sol mode change 100644 => 100755 contracts/lib/ownership/Ownable.sol mode change 100644 => 100755 contracts/lib/ownership/Upgradable.sol mode change 100644 => 100755 contracts/lib/ownership/ZapCoordinator.sol mode change 100644 => 100755 contracts/lib/ownership/ZapCoordinatorInterface.sol delete mode 100644 contracts/lib/platform/BTCcontest.sol mode change 100644 => 100755 contracts/lib/platform/Client.sol mode change 100644 => 100755 contracts/lib/platform/ERCDotFactory.sol mode change 100644 => 100755 contracts/lib/platform/EthAdapter.sol mode change 100644 => 100755 contracts/lib/platform/EthGatedMarket.sol delete mode 100644 contracts/lib/platform/MostBondedByDateContest.sol mode change 100644 => 100755 contracts/lib/platform/OnChainProvider.sol mode change 100644 => 100755 contracts/lib/platform/PiecewiseLogic.sol delete mode 100644 contracts/lib/platform/SampleContest.sol mode change 100644 => 100755 contracts/lib/platform/SampleOnChainOracle.sol mode change 100644 => 100755 contracts/lib/platform/Telegram.sol mode change 100644 => 100755 contracts/lib/platform/TestContracts.sol mode change 100644 => 100755 contracts/lib/platform/TokenAdapter.sol mode change 100644 => 100755 contracts/lib/platform/TokenDotFactory.sol mode change 100644 => 100755 contracts/lib/token/FactoryTokenInterface.sol mode change 100644 => 100755 contracts/lib/token/Token.sol mode change 100644 => 100755 contracts/lib/token/TokenFactory.sol mode change 100644 => 100755 contracts/lib/token/TokenFactoryInterface.sol mode change 100644 => 100755 contracts/platform/arbiter/Arbiter.sol mode change 100644 => 100755 contracts/platform/arbiter/ArbiterInterface.sol mode change 100644 => 100755 contracts/platform/bondage/Bondage.sol mode change 100644 => 100755 contracts/platform/bondage/BondageInterface.sol mode change 100644 => 100755 contracts/platform/bondage/currentCost/CurrentCost.sol mode change 100644 => 100755 contracts/platform/bondage/currentCost/CurrentCostInterface.sol mode change 100644 => 100755 contracts/platform/database/Database.sol mode change 100644 => 100755 contracts/platform/database/DatabaseInterface.sol mode change 100644 => 100755 contracts/platform/dispatch/Dispatch.sol mode change 100644 => 100755 contracts/platform/dispatch/DispatchInterface.sol mode change 100644 => 100755 contracts/platform/registry/Registry.sol mode change 100644 => 100755 contracts/platform/registry/RegistryInterface.sol diff --git a/contracts/lib/ERC20.sol b/contracts/lib/ERC20.sol old mode 100644 new mode 100755 index 3aaffff..1ffe7c9 --- a/contracts/lib/ERC20.sol +++ b/contracts/lib/ERC20.sol @@ -1,8 +1,8 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; contract ERC20Basic { uint256 public totalSupply; - function balanceOf(address who) public constant returns (uint256); + function balanceOf(address who) public pure returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); } @@ -11,7 +11,7 @@ contract ERC20 is ERC20Basic { string public name; string public symbol; uint256 public decimals; - function allowance(address owner, address spender) public constant returns (uint256); + function allowance(address owner, address spender) public pure returns (uint256); function transferFrom(address from, address to, uint256 value) public returns (bool); function approve(address spender, uint256 value) public returns (bool); event Approval(address indexed owner, address indexed spender, uint256 value); diff --git a/contracts/lib/lifecycle/Destructible.sol b/contracts/lib/lifecycle/Destructible.sol old mode 100644 new mode 100755 index 25ed47d..c16b9a2 --- a/contracts/lib/lifecycle/Destructible.sol +++ b/contracts/lib/lifecycle/Destructible.sol @@ -1,9 +1,10 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; import "../ownership/Ownable.sol"; contract Destructible is Ownable { function selfDestruct() public onlyOwner { - selfdestruct(owner); + require(owner == msg.sender); + selfdestruct(msg.sender); } } diff --git a/contracts/lib/ownership/Ownable.sol b/contracts/lib/ownership/Ownable.sol old mode 100644 new mode 100755 index 848fab4..88ca3b2 --- a/contracts/lib/ownership/Ownable.sol +++ b/contracts/lib/ownership/Ownable.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; contract Ownable { address public owner; diff --git a/contracts/lib/ownership/Upgradable.sol b/contracts/lib/ownership/Upgradable.sol old mode 100644 new mode 100755 index 0d4c88a..509ef67 --- a/contracts/lib/ownership/Upgradable.sol +++ b/contracts/lib/ownership/Upgradable.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; import "./ZapCoordinatorInterface.sol"; diff --git a/contracts/lib/ownership/ZapCoordinator.sol b/contracts/lib/ownership/ZapCoordinator.sol old mode 100644 new mode 100755 index b3ab639..b12564e --- a/contracts/lib/ownership/ZapCoordinator.sol +++ b/contracts/lib/ownership/ZapCoordinator.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; import "./Upgradable.sol"; import "./ZapCoordinatorInterface.sol"; @@ -17,7 +17,7 @@ contract ZapCoordinator is ZapCoordinatorInterface { DatabaseInterface public db; // used for adding contracts like Database and ZapToken - function addImmutableContract(string contractName, address newAddress) external onlyOwner { + function addImmutableContract(string calldata contractName, address newAddress) external onlyOwner { assert(contracts[contractName] == address(0)); contracts[contractName] = newAddress; @@ -27,7 +27,7 @@ contract ZapCoordinator is ZapCoordinatorInterface { } // used for modifying an existing contract or adding a new contract to the system - function updateContract(string contractName, address newAddress) external onlyOwner { + function updateContract(string calldata contractName, address newAddress) external onlyOwner { address prev = contracts[contractName]; if (prev == address(0) ) { // First time adding this contract @@ -43,11 +43,11 @@ contract ZapCoordinator is ZapCoordinatorInterface { contracts[contractName] = newAddress; } - function getContractName(uint index) public view returns (string) { + function getContractName(uint index) public view returns (string memory) { return loadedContracts[index]; } - function getContract(string contractName) public view returns (address) { + function getContract(string memory contractName) public view returns (address) { return contracts[contractName]; } diff --git a/contracts/lib/ownership/ZapCoordinatorInterface.sol b/contracts/lib/ownership/ZapCoordinatorInterface.sol old mode 100644 new mode 100755 index f816a4d..917903d --- a/contracts/lib/ownership/ZapCoordinatorInterface.sol +++ b/contracts/lib/ownership/ZapCoordinatorInterface.sol @@ -1,11 +1,11 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; import "./Ownable.sol"; contract ZapCoordinatorInterface is Ownable { - function addImmutableContract(string contractName, address newAddress) external; - function updateContract(string contractName, address newAddress) external; - function getContractName(uint index) public view returns (string); - function getContract(string contractName) public view returns (address); + function addImmutableContract(string calldata contractName, address newAddress) external; + function updateContract(string calldata contractName, address newAddress) external; + function getContractName(uint index) public view returns (string memory); + function getContract(string memory contractName) public view returns (address); function updateAllDependencies() external; } diff --git a/contracts/lib/platform/BTCcontest.sol b/contracts/lib/platform/BTCcontest.sol deleted file mode 100644 index b583339..0000000 --- a/contracts/lib/platform/BTCcontest.sol +++ /dev/null @@ -1,76 +0,0 @@ -pragma solidity ^0.4.25; -import "./SampleContest.sol"; -import "../ownership/ZapCoordinatorInterface.sol"; -import "../../platform/dispatch/DispatchInterface.sol"; -import "../token/FactoryTokenInterface.sol"; -import "../../platform/bondage/currentCost/CurrentCostInterface.sol"; -import "./Client.sol"; - - -contract BTCcontest is Ownable, ClientIntArray { - SampleContest public contest; - ZapCoordinatorInterface public coordinator; - address public oracle; - uint256 public query_id; - uint256 public startPrice; - bytes32 public upEndpoint; - bytes32 public downEndpoint; - - constructor( - address _cord, - address _contest, - uint256 _startPrice, - bytes32 _upEndpoint, - bytes32 _downEndpoint - ){ - oracle = msg.sender; - contest = SampleContest(_contest); - startPrice = _startPrice; - coordinator = ZapCoordinatorInterface(_cord); - require(contest.isEndpointValid(_upEndpoint) && contest.isEndpointValid(_downEndpoint),"Endpoints are not valid"); - upEndpoint = _upEndpoint; - downEndpoint = _downEndpoint; - address bondageAddress = coordinator.getContract("BONDAGE"); - BondageInterface bondage = BondageInterface(bondageAddress); - FactoryTokenInterface reserveToken = FactoryTokenInterface(coordinator.getContract("ZAP_TOKEN")); - //get reserve value to send - reserveToken.approve(address(bondageAddress),~uint256(0)); - - } - - function bondToCoincap(address _coincap,bytes32 _endpoint,uint256 _numDots)public returns (bool){ - address bondageAddress = coordinator.getContract("BONDAGE"); - BondageInterface bondage = BondageInterface(bondageAddress); - FactoryTokenInterface reserveToken = FactoryTokenInterface(coordinator.getContract("ZAP_TOKEN")); - //get reserve value to send - bondage.bond(_coincap,_endpoint,_numDots); - return true; - - } - function queryToSettle(address _coincap,bytes32 _endpoint) public returns(uint256){ - require(msg.sender == oracle, "Only Oracle owner can call query to settle"); - address dispatchAddress = coordinator.getContract("DISPATCH"); - DispatchInterface dispatch = DispatchInterface(dispatchAddress); - bytes32[] memory params = new bytes32[](0); - return dispatch.query(_coincap,"BTC",_endpoint,params); - } - - - - function callback(uint256 _id, int[] responses) external { - address dispatchAddress = coordinator.getContract("DISPATCH"); - require(address(msg.sender)==address(dispatchAddress),"Only accept response from dispatch"); - require(contest.getStatus()==1,"Contest is not in initialized state"); //2 is the ReadyToSettle enum value - uint256 price = uint256(responses[0]); - bytes32[] memory endpoints = contest.getEndpoints(); - for(uint256 i=0;i startPrice){ - return contest.judge(endpoints[i]); - } - if(endpoints[i]==downEndpoint && price endtime, "Contest is still active"); - address bondageAddress = coordinator.getContract("BONDAGE"); - BondageInterface bondage = BondageInterface(bondageAddress); - bytes32[] memory endpoints = contest.getEndpoints(); - bytes32 winner; - uint256 max = 0; - uint256 bound; - for (uint256 i = 0; i < endpoints.length; i++) { - bound = bondage.getZapBound(address(contest), endpoints[i]); - if (bound > max) { - max = bound; - winner = endpoints[i]; - } - } - contest.judge(winner); - } - - function getEndTime() returns(uint256) { - return endtime; - } -} diff --git a/contracts/lib/platform/OnChainProvider.sol b/contracts/lib/platform/OnChainProvider.sol old mode 100644 new mode 100755 index 40cd368..708ddb6 --- a/contracts/lib/platform/OnChainProvider.sol +++ b/contracts/lib/platform/OnChainProvider.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; contract OnChainProvider { /// @dev function for requesting data from on-chain provider @@ -6,5 +6,5 @@ contract OnChainProvider { /// @param userQuery query string /// @param endpoint endpoint specifier ala 'smart_contract' /// @param endpointParams endpoint-specific params - function receive(uint256 id, string userQuery, bytes32 endpoint, bytes32[] endpointParams, bool onchainSubscriber) external; + function receive(uint256 id, string calldata userQuery, bytes32 endpoint, bytes32[] calldata endpointParams, bool onchainSubscriber) external; } diff --git a/contracts/lib/platform/PiecewiseLogic.sol b/contracts/lib/platform/PiecewiseLogic.sol old mode 100644 new mode 100755 index 8df7a49..e1129d5 --- a/contracts/lib/platform/PiecewiseLogic.sol +++ b/contracts/lib/platform/PiecewiseLogic.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; library PiecewiseLogic { function sumOfPowers(uint n, uint i) internal pure returns (uint) { @@ -16,7 +16,7 @@ library PiecewiseLogic { return 0; } - function evaluateFunction(int[] curve, uint a, uint b) internal pure returns (int) { + function evaluateFunction(int[] memory curve, uint a, uint b) internal pure returns (int) { uint i = 0; int sum = 0; @@ -50,7 +50,7 @@ library PiecewiseLogic { } } - function evaluatePiece(int[] curve, uint index, uint a, uint b) internal pure returns (int) { + function evaluatePiece(int[] memory curve, uint index, uint a, uint b) internal pure returns (int) { int sum = 0; uint len = uint(curve[index]); uint base = index + 1; diff --git a/contracts/lib/platform/SampleContest.sol b/contracts/lib/platform/SampleContest.sol deleted file mode 100644 index 4f635b8..0000000 --- a/contracts/lib/platform/SampleContest.sol +++ /dev/null @@ -1,316 +0,0 @@ -import "../token/TokenFactoryInterface.sol"; -import "../token/FactoryTokenInterface.sol"; -import "../ownership/ZapCoordinatorInterface.sol"; -import "../../platform/bondage/BondageInterface.sol"; -import "../../platform/bondage/currentCost/CurrentCostInterface.sol"; -import "../../platform/registry/RegistryInterface.sol"; -import "../../platform/bondage/currentCost/CurrentCostInterface.sol"; - -/* -Contest where users can bond to contestant curves which mint tokens( unbondabe*), -winner decided by oracle -contract unbonds from loser curves -holders of winning token allowed to take share of reserve token(zap) which was unbonded from loser curves - -Starting Contest: - - deploys with contest uninitialized: status = Uninitialized - - anyone can initialize new token:backed curve - - owner initializes contest with oracle: status = Initialized - -Ending Contest: - - owner calls close: status = ReadyToSettle - - oracle calls judge to set winning curve: status = Judged - - anyone calls settle, contest unbonds from losing curves: status = Settled - - holders of winnning token call redeem to retrieve their share of reserve token - based on their holding of winning token - - *holders of winning token can optionally unbond -*/ - -contract SampleContest is Ownable { - - CurrentCostInterface currentCost; - FactoryTokenInterface public reserveToken; - ZapCoordinatorInterface public coord; - TokenFactoryInterface public tokenFactory; - BondageInterface bondage; - - enum ContestStatus { - Uninitialized, // - Initialized, // ready for buys - // ReadyToSettle, // ready for judgement - Judged, // winner determined - Settled, // value of winning tokens determined - Canceled // oracle did not respond in time - } - - address public oracle; // address of oracle who will choose the winner - uint256 public ttl; // time allowed before, close and judge. if time expired, allow unbond from all curves - // uint256 public expired = 2**256 -1; // time allowed before, close and judge. if time expired, allow unbond from all curves - bytes32 public winner; // curve identifier of the winner - uint256 public winValue; // final value of the winning token - ContestStatus public status; //state of contest - - mapping(bytes32 => address) public curves; // map of endpoint specifier to token-backed dotaddress - bytes32[] public curves_list; // array of endpoint specifiers - - mapping(address => uint8) public redeemed; // map of address redemption state - address[] public redeemed_list; - - event DotTokenCreated(address tokenAddress); - event Bonded(bytes32 indexed endpoint, uint256 indexed numDots, address indexed sender); - event Unbonded(bytes32 indexed endpoint,uint256 indexed amount, address indexed sender); - - event Initialized(address indexed oracle); - event Closed(); - event Judged(bytes32 winner); - event Settled(uint256 winValue, uint256 winTokens); - event Reset(); - - constructor( - address coordinator, - address factory, - uint256 providerPubKey, - bytes32 providerTitle - ){ - coord = ZapCoordinatorInterface(coordinator); - reserveToken = FactoryTokenInterface(coord.getContract("ZAP_TOKEN")); - //always allow bondage to transfer from wallet - reserveToken.approve(coord.getContract("BONDAGE"), ~uint256(0)); - tokenFactory = TokenFactoryInterface(factory); - - RegistryInterface registry = RegistryInterface(coord.getContract("REGISTRY")); - registry.initiateProvider(providerPubKey, providerTitle); - status = ContestStatus.Uninitialized; - } - -// contest lifecycle - - function initializeContest( - address oracleAddress, - uint256 _ttl - ) onlyOwner public { - require( status == ContestStatus.Uninitialized, "Contest already initialized"); - oracle = oracleAddress; - ttl = _ttl + block.number; - status = ContestStatus.Initialized; - emit Initialized(oracle); - } - - // function close() onlyOwner { - // status = ContestStatus.ReadyToSettle; - // expired = block.number + ttl; - // emit Closed(); - // } - - function judge(bytes32 endpoint) { - require( status == ContestStatus.Initialized, "Contest not initialized" ); - require( msg.sender == oracle, "Only designated Oracle can judge"); - require(block.number < ttl, "Contest expired, refund in process"); - winner = endpoint; - status = ContestStatus.Judged; - emit Judged(winner); - } - - function settle() public { - require( status == ContestStatus.Judged, "winner not determined"); - - bondage = BondageInterface(coord.getContract("BONDAGE")); - // how many winning dots - uint256 numWin = bondage.getDotsIssued(address(this), winner); - // redeemable value of each dot token - uint256 dots; - for( uint256 i = 0; i < curves_list.length; i++) { - if(curves_list[i]!=winner){ - dots = bondage.getDotsIssued(address(this), curves_list[i]); - if( dots > 0) { - bondage.unbond(address(this), curves_list[i], dots); - } - } - } - winValue = reserveToken.balanceOf(address(this)) / numWin; - - status = ContestStatus.Settled; - emit Settled(winValue, numWin); - } - - - //TODO ensure all has been redeemed or enough time has elasped - function reset() public { - require(msg.sender == oracle); - require(status == ContestStatus.Settled || status == ContestStatus.Canceled, "contest not settled"); - if( status == ContestStatus.Canceled ) { - require(reserveToken.balanceOf(address(this)) == 0, "funds remain"); - } - - delete redeemed_list; - delete curves_list; - status = ContestStatus.Initialized; - emit Reset(); - } - -/// TokenDotFactory methods - - function initializeCurve( - bytes32 endpoint, - bytes32 symbol, - int256[] curve - ) public returns(address) { - // require(status==ContestStatus.Initialized,"Contest is not initalized") - require(curves[endpoint] == 0, "Curve endpoint already exists or used in the past. Please choose a new endpoint"); - - RegistryInterface registry = RegistryInterface(coord.getContract("REGISTRY")); - registry.initiateProviderCurve(endpoint, curve, address(this)); - - curves[endpoint] = newToken(bytes32ToString(endpoint), bytes32ToString(symbol)); - curves_list.push(endpoint); - registry.setProviderParameter(endpoint, toBytes(curves[endpoint])); - - DotTokenCreated(curves[endpoint]); - return curves[endpoint]; - } - - //whether this contract holds tokens or coming from msg.sender,etc - function bond(bytes32 endpoint, uint numDots) public { - require( status == ContestStatus.Initialized, " contest is not initiated"); - - bondage = BondageInterface(coord.getContract("BONDAGE")); - uint256 issued = bondage.getDotsIssued(address(this), endpoint); - - CurrentCostInterface cost = CurrentCostInterface(coord.getContract("CURRENT_COST")); - uint256 numReserve = cost._costOfNDots(address(this), endpoint, issued + 1, numDots - 1); - - require( - reserveToken.transferFrom(msg.sender, address(this), numReserve), - "insufficient accepted token numDots approved for transfer" - ); - - reserveToken.approve(address(bondage), numReserve); - bondage.bond(address(this), endpoint, numDots); - FactoryTokenInterface(curves[endpoint]).mint(msg.sender, numDots); - emit Bonded(endpoint, numDots, msg.sender); - } - - //whether this contract holds tokens or coming from msg.sender,etc - function unbond(bytes32 endpoint, uint numDots) public returns(uint256) { - - require(status == ContestStatus.Settled, "not ready"); - - bondage = BondageInterface(coord.getContract("BONDAGE")); - uint issued = bondage.getDotsIssued(address(this), endpoint); - - //unbond dots - bondage.unbond(address(this), winner, numDots); - - currentCost = CurrentCostInterface(coord.getContract("CURRENT_COST")); - //get reserve value to send - uint reserveCost = currentCost._costOfNDots(address(this), endpoint, issued + 1 - numDots, numDots - 1); - - FactoryTokenInterface curveToken = FactoryTokenInterface(curves[endpoint]); - - if( status == ContestStatus.Initialized || status == ContestStatus.Canceled) { - //oracle has taken too long to judge winner so unbonds will be allowed for all - require(block.number > ttl, "oracle query not expired."); - // require(status == ContestStatus.Settled, "contest not settled"); - status = ContestStatus.Canceled; - - //unbond dots - //TODO get bound dot then unbond the correct amount ? or unbond all in 1 call - // bondage.unbond(address(this), endpoint, numDots); - - //burn dot backed token - //FIXME only burn the bound tokens ? - curveToken.burnFrom(msg.sender, numDots); - - require(reserveToken.transfer(msg.sender, reserveCost), "transfer failed"); - emit Unbonded(endpoint, reserveCost, msg.sender); - return reserveCost; - } - - else { - - require( status == ContestStatus.Settled, " contest not settled"); - require(redeemed[msg.sender] == 0, "already redeeemed"); - require(winner==endpoint, "only winners can unbond for rewards"); - - //reward user's winning tokens unbond value + share of losing curves reserve token proportional to winning token holdings - uint reward = ( winValue * FactoryTokenInterface(getTokenAddress(winner)).balanceOf(msg.sender) ) + reserveCost; - - //burn user's unbonded tokens - // curveToken.approve(address(this),numDots); - curveToken.burnFrom(msg.sender, numDots); - - reserveToken.transfer(msg.sender, reward); - redeemed[msg.sender] = 1; - - // emit Unbonded(winner, reward, msg.sender); - return reward; - } - } - - function newToken( - string name, - string symbol - ) - internal - returns (address tokenAddress) - { - FactoryTokenInterface token = tokenFactory.create(name, symbol); - tokenAddress = address(token); - return tokenAddress; - } - - function getTokenAddress(bytes32 endpoint) public view returns(address) { - RegistryInterface registry = RegistryInterface(coord.getContract("REGISTRY")); - return bytesToAddr(registry.getProviderParameter(address(this), endpoint)); - } - - function getEndpoints() public view returns(bytes32[]){ - return curves_list; - } - - function getStatus() public view returns(uint256){ - return uint(status); - } - - function isEndpointValid(bytes32 _endpoint) public view returns(bool){ - for(uint256 i=0; i 0; i--) { - uint c = uint(b[i]); - uint to_inc = c * ( 16 ** ((b.length - i-1) * 2)); - result += to_inc; - } - return address(result); - } -} diff --git a/contracts/lib/platform/SampleOnChainOracle.sol b/contracts/lib/platform/SampleOnChainOracle.sol old mode 100644 new mode 100755 index 82cbe1b..c4c98fc --- a/contracts/lib/platform/SampleOnChainOracle.sol +++ b/contracts/lib/platform/SampleOnChainOracle.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; import "../ownership/ZapCoordinatorInterface.sol"; import "../../platform/dispatch/DispatchInterface.sol"; @@ -19,39 +19,39 @@ contract SampleOnChainOracle is OnChainProvider, Ownable { address coordinator, uint256 providerPubKey, bytes32 providerTitle - ){ + ) public { coord = ZapCoordinatorInterface(coordinator); - RegistryInterface registry = RegistryInterface(coord.getContract("REGISTRY")); + registry = RegistryInterface(coord.getContract("REGISTRY")); registry.initiateProvider(providerPubKey, providerTitle); } //initialize an endpoint curve function initializeCurve( bytes32 specifier, - int256[] curve + int256[] memory curve ) onlyOwner public returns(bool) { - RegistryInterface registry = RegistryInterface(coord.getContract("REGISTRY")); + registry = RegistryInterface(coord.getContract("REGISTRY")); require(registry.isProviderInitiated(address(this)), "Provider not intiialized"); return registry.initiateProviderCurve(specifier, curve, address(0)); } - function setProviderParameter(bytes32 key, bytes value) onlyOwner public { + function setProviderParameter(bytes32 key, bytes memory value) onlyOwner public { registry = RegistryInterface(coord.getContract('REGISTRY')); registry.setProviderParameter(key, value); } - function setEndpointParams(bytes32 endpoint, bytes32[] endpointParams) onlyOwner public { + function setEndpointParams(bytes32 endpoint, bytes32[] memory endpointParams) onlyOwner public { registry = RegistryInterface(coord.getContract('REGISTRY')); registry.setEndpointParams(endpoint, endpointParams); } // middleware function for handling queries - function receive(uint256 id, string userQuery, bytes32 endpoint, bytes32[] endpointParams, bool onchainSubscriber) external { + function receive(uint256 id, string calldata userQuery, bytes32 endpoint, bytes32[] calldata endpointParams, bool onchainSubscriber) external { emit RecievedQuery(userQuery, endpoint, endpointParams); diff --git a/contracts/lib/platform/Telegram.sol b/contracts/lib/platform/Telegram.sol old mode 100644 new mode 100755 index 2dbc764..e73d991 --- a/contracts/lib/platform/Telegram.sol +++ b/contracts/lib/platform/Telegram.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; import "../../platform/registry/RegistryInterface.sol"; import "./OnChainProvider.sol"; @@ -14,7 +14,7 @@ contract Telegram is OnChainProvider { RegistryInterface registry; // middleware function for handling queries - function receive(uint256 /* id */, string /* userQuery */, bytes32 /* endpoint */, bytes32[] /* endpointParams */, bool /* onchainSubscriber*/) external { + function receive(uint256 /* id */, string calldata /* userQuery */, bytes32 /* endpoint */, bytes32[] calldata /* endpointParams */, bool /* onchainSubscriber*/) external { } constructor(address registryAddress) public{ diff --git a/contracts/lib/platform/TestContracts.sol b/contracts/lib/platform/TestContracts.sol old mode 100644 new mode 100755 index 6a2fd58..e926dca --- a/contracts/lib/platform/TestContracts.sol +++ b/contracts/lib/platform/TestContracts.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; import "./Client.sol"; import "../../platform/dispatch/DispatchInterface.sol"; @@ -31,7 +31,7 @@ contract TestProvider is OnChainProvider { RegistryInterface registry; // middleware function for handling queries - function receive(uint256 id, string userQuery, bytes32 endpoint, bytes32[] endpointParams, bool onchainSubscriber) external { + function receive(uint256 id, string calldata userQuery, bytes32 endpoint, bytes32[] calldata endpointParams, bool onchainSubscriber) external { emit RecievedQuery(userQuery, endpoint, endpointParams); if(AM_A_BAD_ORACLE) return; bytes32 _endpoint = endpoint; @@ -73,19 +73,19 @@ contract TestProvider is OnChainProvider { // return Hello World to query-maker - function endpoint1(uint256 id, string /* userQuery */, bytes32[] /* endpointParams */) internal{ + function endpoint1(uint256 id, string memory/* userQuery */, bytes32[] memory /* endpointParams */) internal{ DispatchInterface(msg.sender).respond1(id, "Hello World"); } // return the hash of the query - function endpoint2(uint256 id, string userQuery, bytes32[] /* endpointParams */) internal{ + function endpoint2(uint256 id, string memory userQuery, bytes32[] memory /* endpointParams */) internal{ // endpointParams string memory reversed = reverseString(userQuery); DispatchInterface(msg.sender).respond1(id, reversed); } // returns the sum of all values in endpointParams - function endpoint3(uint256 id, string /* userQuery */, bytes32[] endpointParams) internal{ + function endpoint3(uint256 id, string memory /* userQuery */, bytes32[] memory endpointParams) internal{ uint sum = 0; for(uint i = 0; i 0; i--) { - uint c = uint(b[i]); - uint to_inc = c * ( 16 ** ((b.length - i-1) * 2)); - result += to_inc; - } - return address(result); + function bytesToAddr (bytes memory bys) public pure returns (address) { + address addr = address(0); + + assembly { + addr := mload(add(bys,20)) + } + return address(addr); } diff --git a/contracts/lib/token/FactoryTokenInterface.sol b/contracts/lib/token/FactoryTokenInterface.sol old mode 100644 new mode 100755 index 8d1d305..006be69 --- a/contracts/lib/token/FactoryTokenInterface.sol +++ b/contracts/lib/token/FactoryTokenInterface.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; import "../ownership/Ownable.sol"; diff --git a/contracts/lib/token/Token.sol b/contracts/lib/token/Token.sol old mode 100644 new mode 100755 index 231c7ca..275c1f5 --- a/contracts/lib/token/Token.sol +++ b/contracts/lib/token/Token.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; import "./FactoryTokenInterface.sol"; @@ -61,7 +61,7 @@ contract FactoryToken is FactoryTokenInterface { string public name; string public symbol; - uint8 public decimals = 3; + uint8 public decimals = 18; uint256 totalSupply_; mapping(address => mapping(address => uint256)) internal allowed; @@ -85,7 +85,7 @@ contract FactoryToken is FactoryTokenInterface { _; } - constructor(string _name, string _symbol) public { + constructor(string memory _name, string memory _symbol) public { name = _name; symbol = _symbol; } diff --git a/contracts/lib/token/TokenFactory.sol b/contracts/lib/token/TokenFactory.sol old mode 100644 new mode 100755 index ed26c3e..e107f74 --- a/contracts/lib/token/TokenFactory.sol +++ b/contracts/lib/token/TokenFactory.sol @@ -1,14 +1,11 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; import "./Token.sol"; import "./TokenFactoryInterface.sol"; contract TokenFactory is TokenFactoryInterface { - function TokenFactory(){ - } - - function create(string _name, string _symbol) public returns (FactoryTokenInterface) { + function create(string memory _name, string memory _symbol) public returns (FactoryTokenInterface) { FactoryToken token = new FactoryToken(_name, _symbol); token.transferOwnership(msg.sender); return token; diff --git a/contracts/lib/token/TokenFactoryInterface.sol b/contracts/lib/token/TokenFactoryInterface.sol old mode 100644 new mode 100755 index d8206c3..82e5527 --- a/contracts/lib/token/TokenFactoryInterface.sol +++ b/contracts/lib/token/TokenFactoryInterface.sol @@ -1,7 +1,7 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; import "./FactoryTokenInterface.sol"; contract TokenFactoryInterface { - function create(string _name, string _symbol) public returns (FactoryTokenInterface); + function create(string memory _name, string memory _symbol) public returns (FactoryTokenInterface); } diff --git a/contracts/platform/arbiter/Arbiter.sol b/contracts/platform/arbiter/Arbiter.sol old mode 100644 new mode 100755 index 9c58203..197df2d --- a/contracts/platform/arbiter/Arbiter.sol +++ b/contracts/platform/arbiter/Arbiter.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; // v1.0 import "../../lib/ownership/Upgradable.sol"; @@ -59,7 +59,7 @@ contract Arbiter is Destructible, ArbiterInterface, Upgradable { /// @param receiver address /// @param endpoint Endpoint specifier /// @param params arbitrary params to be passed - function passParams(address receiver, bytes32 endpoint, bytes32[] params) public { + function passParams(address receiver, bytes32 endpoint, bytes32[] memory params) public { emit ParamsPassed(msg.sender, receiver, endpoint, params); } @@ -72,7 +72,7 @@ contract Arbiter is Destructible, ArbiterInterface, Upgradable { function initiateSubscription( address providerAddress, // bytes32 endpoint, // - bytes32[] endpointParams, // + bytes32[] memory endpointParams, // uint256 publicKey, // Public key of the purchaser uint64 blocks // ) diff --git a/contracts/platform/arbiter/ArbiterInterface.sol b/contracts/platform/arbiter/ArbiterInterface.sol old mode 100644 new mode 100755 index 7a50c2a..c2af22e --- a/contracts/platform/arbiter/ArbiterInterface.sol +++ b/contracts/platform/arbiter/ArbiterInterface.sol @@ -1,9 +1,9 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; contract ArbiterInterface { - function initiateSubscription(address, bytes32, bytes32[], uint256, uint64) public; + function initiateSubscription(address, bytes32, bytes32[] memory, uint256, uint64) public; function getSubscription(address, address, bytes32) public view returns (uint64, uint96, uint96); function endSubscriptionProvider(address, bytes32) public; function endSubscriptionSubscriber(address, bytes32) public; - function passParams(address receiver, bytes32 endpoint, bytes32[] params) public; + function passParams(address receiver, bytes32 endpoint, bytes32[] memory params) public; } diff --git a/contracts/platform/bondage/Bondage.sol b/contracts/platform/bondage/Bondage.sol old mode 100644 new mode 100755 index c6ee849..fc65c0b --- a/contracts/platform/bondage/Bondage.sol +++ b/contracts/platform/bondage/Bondage.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; import "../../lib/lifecycle/Destructible.sol"; import "../../lib/ownership/Upgradable.sol"; @@ -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"); if (!isProviderInitialized(holderAddress, oracleAddress)) { setProviderInitialized(holderAddress, oracleAddress); @@ -252,13 +252,14 @@ contract Bondage is Destructible, BondageInterface, Upgradable { } /**** Get Methods ****/ - function isProviderInitialized(address holderAddress, address oracleAddress) public view returns (bool) { + function isProviderInitialized(address holderAddress, address oracleAddress) public payable returns (bool) { return db.getNumber(keccak256(abi.encodePacked('holders', holderAddress, 'initialized', oracleAddress))) == 1 ? true : false; } /// @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')))); + function getEndpointBroker(address oracleAddress, bytes32 _endpoint) public payable returns (address) { + db.setBytes32(keccak256(abi.encodePacked('oracles', oracleAddress, _endpoint, 'broker')), _endpoint); + return address(db); } function getNumEscrow(address holderAddress, address oracleAddress, bytes32 endpoint) public view returns (uint256) { diff --git a/contracts/platform/bondage/BondageInterface.sol b/contracts/platform/bondage/BondageInterface.sol old mode 100644 new mode 100755 index 3d079ec..fd8fda5 --- a/contracts/platform/bondage/BondageInterface.sol +++ b/contracts/platform/bondage/BondageInterface.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; contract BondageInterface { function bond(address, bytes32, uint256) external returns(uint256); diff --git a/contracts/platform/bondage/currentCost/CurrentCost.sol b/contracts/platform/bondage/currentCost/CurrentCost.sol old mode 100644 new mode 100755 index bf7edde..de84343 --- a/contracts/platform/bondage/currentCost/CurrentCost.sol +++ b/contracts/platform/bondage/currentCost/CurrentCost.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; import "../../../lib/lifecycle/Destructible.sol"; import "../../../lib/ownership/Upgradable.sol"; diff --git a/contracts/platform/bondage/currentCost/CurrentCostInterface.sol b/contracts/platform/bondage/currentCost/CurrentCostInterface.sol old mode 100644 new mode 100755 index 941cca7..ef62af1 --- a/contracts/platform/bondage/currentCost/CurrentCostInterface.sol +++ b/contracts/platform/bondage/currentCost/CurrentCostInterface.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; contract CurrentCostInterface { function _currentCostOfDot(address, bytes32, uint256) public view returns (uint256); diff --git a/contracts/platform/database/Database.sol b/contracts/platform/database/Database.sol old mode 100644 new mode 100755 index 66312cc..853c5c5 --- a/contracts/platform/database/Database.sol +++ b/contracts/platform/database/Database.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; import "./DatabaseInterface.sol"; import "../../lib/ownership/Ownable.sol"; @@ -43,25 +43,25 @@ contract Database is Ownable, DatabaseInterface { } /*** Bytes ***/ - function getBytes(bytes32 key) external view returns(bytes) { + function getBytes(bytes32 key) external view returns(bytes memory) { return data_bytes[key]; } - function setBytes(bytes32 key, bytes value) external storageOnly { + function setBytes(bytes32 key, bytes calldata value) external storageOnly { data_bytes[key] = value; } /*** String ***/ - function getString(bytes32 key) external view returns(string) { + function getString(bytes32 key) external view returns(string memory) { return string(data_bytes[key]); } - function setString(bytes32 key, string value) external storageOnly { + function setString(bytes32 key, string calldata value) external storageOnly { data_bytes[key] = bytes(value); } /*** Bytes Array ***/ - function getBytesArray(bytes32 key) external view returns (bytes32[]) { + function getBytesArray(bytes32 key) external view returns (bytes32[] memory) { return data_bytesArray[key]; } @@ -81,12 +81,12 @@ contract Database is Ownable, DatabaseInterface { data_bytesArray[key][index] = value; } - function setBytesArray(bytes32 key, bytes32[] value) external storageOnly { + function setBytesArray(bytes32 key, bytes32[] calldata value) external storageOnly { data_bytesArray[key] = value; } /*** Int Array ***/ - function getIntArray(bytes32 key) external view returns (int[]) { + function getIntArray(bytes32 key) external view returns (int[] memory) { return data_intArray[key]; } @@ -106,12 +106,12 @@ contract Database is Ownable, DatabaseInterface { data_intArray[key][index] = value; } - function setIntArray(bytes32 key, int[] value) external storageOnly { + function setIntArray(bytes32 key, int[] calldata value) external storageOnly { data_intArray[key] = value; } /*** Address Array ***/ - function getAddressArray(bytes32 key) external view returns (address[]) { + function getAddressArray(bytes32 key) external view returns (address[] memory) { return data_addressArray[key]; } @@ -131,7 +131,7 @@ contract Database is Ownable, DatabaseInterface { data_addressArray[key][index] = value; } - function setAddressArray(bytes32 key, address[] value) external storageOnly { + function setAddressArray(bytes32 key, address[] calldata value) external storageOnly { data_addressArray[key] = value; } } diff --git a/contracts/platform/database/DatabaseInterface.sol b/contracts/platform/database/DatabaseInterface.sol old mode 100644 new mode 100755 index f47b7e4..a6593c4 --- a/contracts/platform/database/DatabaseInterface.sol +++ b/contracts/platform/database/DatabaseInterface.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; import "../../lib/ownership/Ownable.sol"; @@ -11,30 +11,30 @@ contract DatabaseInterface is Ownable { function getNumber(bytes32 key) external view returns(uint256); function setNumber(bytes32 key, uint256 value) external; /*** Bytes ***/ - function getBytes(bytes32 key) external view returns(bytes); - function setBytes(bytes32 key, bytes value) external; + function getBytes(bytes32 key) external view returns(bytes memory); + function setBytes(bytes32 key, bytes calldata value) external; /*** String ***/ - function getString(bytes32 key) external view returns(string); - function setString(bytes32 key, string value) external; + function getString(bytes32 key) external view returns(string memory); + function setString(bytes32 key, string calldata value) external; /*** Bytes Array ***/ - function getBytesArray(bytes32 key) external view returns (bytes32[]); + function getBytesArray(bytes32 key) external view returns (bytes32[] memory); function getBytesArrayIndex(bytes32 key, uint256 index) external view returns (bytes32); function getBytesArrayLength(bytes32 key) external view returns (uint256); function pushBytesArray(bytes32 key, bytes32 value) external; function setBytesArrayIndex(bytes32 key, uint256 index, bytes32 value) external; - function setBytesArray(bytes32 key, bytes32[] value) external; + function setBytesArray(bytes32 key, bytes32[] calldata value) external; /*** Int Array ***/ - function getIntArray(bytes32 key) external view returns (int[]); + function getIntArray(bytes32 key) external view returns (int[] memory); function getIntArrayIndex(bytes32 key, uint256 index) external view returns (int); function getIntArrayLength(bytes32 key) external view returns (uint256); function pushIntArray(bytes32 key, int value) external; function setIntArrayIndex(bytes32 key, uint256 index, int value) external; - function setIntArray(bytes32 key, int[] value) external; + function setIntArray(bytes32 key, int[] calldata value) external; /*** Address Array ***/ - function getAddressArray(bytes32 key) external view returns (address[]); + function getAddressArray(bytes32 key) external view returns (address[] memory); function getAddressArrayIndex(bytes32 key, uint256 index) external view returns (address); function getAddressArrayLength(bytes32 key) external view returns (uint256); function pushAddressArray(bytes32 key, address value) external; function setAddressArrayIndex(bytes32 key, uint256 index, address value) external; - function setAddressArray(bytes32 key, address[] value) external; + function setAddressArray(bytes32 key, address[] calldata value) external; } diff --git a/contracts/platform/dispatch/Dispatch.sol b/contracts/platform/dispatch/Dispatch.sol old mode 100644 new mode 100755 index e61e39a..06c8480 --- a/contracts/platform/dispatch/Dispatch.sol +++ b/contracts/platform/dispatch/Dispatch.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; // v1.0 import "../../lib/ownership/Upgradable.sol"; @@ -111,9 +111,9 @@ contract Dispatch is Destructible, DispatchInterface, Upgradable { /// @dev Called by user contract function query( address provider, // data provider address - string userQuery, // query string + string calldata userQuery, // query string bytes32 endpoint, // endpoint specifier ala 'smart_contract' - bytes32[] endpointParams // endpoint-specific params + bytes32[] calldata endpointParams // endpoint-specific params ) external returns (uint256 id) @@ -198,7 +198,7 @@ contract Dispatch is Destructible, DispatchInterface, Upgradable { /// @dev Parameter-count specific method called by data provider in response function respondBytes32Array( uint256 id, - bytes32[] response + bytes32[] calldata response ) external returns (bool) @@ -217,7 +217,7 @@ contract Dispatch is Destructible, DispatchInterface, Upgradable { /// @dev Parameter-count specific method called by data provider in response function respondIntArray( uint256 id, - int[] response + int[] calldata response ) external returns (bool) @@ -237,7 +237,7 @@ contract Dispatch is Destructible, DispatchInterface, Upgradable { /// @dev Parameter-count specific method called by data provider in response function respond1( uint256 id, - string response + string calldata response ) external returns (bool) @@ -257,8 +257,8 @@ contract Dispatch is Destructible, DispatchInterface, Upgradable { /// @dev Parameter-count specific method called by data provider in response function respond2( uint256 id, - string response1, - string response2 + string calldata response1, + string calldata response2 ) external returns (bool) @@ -279,9 +279,9 @@ contract Dispatch is Destructible, DispatchInterface, Upgradable { /// @dev Parameter-count specific method called by data provider in response function respond3( uint256 id, - string response1, - string response2, - string response3 + string calldata response1, + string calldata response2, + string calldata response3 ) external returns (bool) @@ -302,10 +302,10 @@ contract Dispatch is Destructible, DispatchInterface, Upgradable { /// @dev Parameter-count specific method called by data provider in response function respond4( uint256 id, - string response1, - string response2, - string response3, - string response4 + string calldata response1, + string calldata response2, + string calldata response3, + string calldata response4 ) external returns (bool) @@ -357,7 +357,7 @@ contract Dispatch is Destructible, DispatchInterface, Upgradable { /// @dev get user specified query of request /// @param id request id - function getUserQuery(uint256 id) public view returns (string) { + function getUserQuery(uint256 id) public view returns (string memory) { return db.getString(keccak256(abi.encodePacked('queries', id, 'userQuery'))); } @@ -374,7 +374,7 @@ contract Dispatch is Destructible, DispatchInterface, Upgradable { address provider, address subscriber, bytes32 endpoint, - string userQuery, + string memory userQuery, bool onchainSubscriber ) private diff --git a/contracts/platform/dispatch/DispatchInterface.sol b/contracts/platform/dispatch/DispatchInterface.sol old mode 100644 new mode 100755 index 7fc5d22..b98465d --- a/contracts/platform/dispatch/DispatchInterface.sol +++ b/contracts/platform/dispatch/DispatchInterface.sol @@ -1,19 +1,19 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; interface DispatchInterface { - function query(address, string, bytes32, bytes32[]) external returns (uint256); - function respond1(uint256, string) external returns (bool); - function respond2(uint256, string, string) external returns (bool); - function respond3(uint256, string, string, string) external returns (bool); - function respond4(uint256, string, string, string, string) external returns (bool); - function respondBytes32Array(uint256, bytes32[]) external returns (bool); - function respondIntArray(uint256,int[] ) external returns (bool); + function query(address, string calldata, bytes32, bytes32[] calldata) external returns (uint256); + function respond1(uint256, string calldata) external returns (bool); + function respond2(uint256, string calldata, string calldata) external returns (bool); + function respond3(uint256, string calldata, string calldata, string calldata) external returns (bool); + function respond4(uint256, string calldata, string calldata, string calldata, string calldata) external returns (bool); + function respondBytes32Array(uint256, bytes32[] calldata) external returns (bool); + function respondIntArray(uint256,int[] calldata) external returns (bool); function cancelQuery(uint256) external; - function getProvider(uint256 id) public view returns (address); - function getSubscriber(uint256 id) public view returns (address); - function getEndpoint(uint256 id) public view returns (bytes32); - function getStatus(uint256 id) public view returns (uint256); - function getCancel(uint256 id) public view returns (uint256); - function getUserQuery(uint256 id) public view returns (string); - function getSubscriberOnchain(uint256 id) public view returns (bool); + function getProvider(uint256 id) external view returns (address); + function getSubscriber(uint256 id) external view returns (address); + function getEndpoint(uint256 id) external view returns (bytes32); + function getStatus(uint256 id) external view returns (uint256); + function getCancel(uint256 id) external view returns (uint256); + function getUserQuery(uint256 id) external view returns (string memory); + function getSubscriberOnchain(uint256 id) external view returns (bool); } diff --git a/contracts/platform/registry/Registry.sol b/contracts/platform/registry/Registry.sol old mode 100644 new mode 100755 index 39fbd27..8358c72 --- a/contracts/platform/registry/Registry.sol +++ b/contracts/platform/registry/Registry.sol @@ -1,4 +1,4 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; // v1.0 import "../../lib/lifecycle/Destructible.sol"; @@ -56,7 +56,7 @@ contract Registry is Destructible, RegistryInterface, Upgradable { /// @param broker address for endpoint. if non-zero address, only this address will be able to bond/unbond function initiateProviderCurve( bytes32 endpoint, - int256[] curve, + int256[] memory curve, address broker ) public @@ -70,16 +70,22 @@ contract Registry is Destructible, RegistryInterface, Upgradable { require(endpoint != bytes32(0), "Error: Can't initiate null endpoint"); setCurve(msg.sender, endpoint, curve); + db.pushBytesArray(keccak256(abi.encodePacked('oracles', msg.sender, 'endpoints')), endpoint); - 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)); emit NewCurve(msg.sender, endpoint, curve, broker); return true; } + function toBytes(address a) public pure returns (bytes memory) { + return abi.encodePacked(a); +} // Sets provider data - function setProviderParameter(bytes32 key, bytes value) public { + function setProviderParameter(bytes32 key, bytes memory value) public { // Provider must be initiated require(isProviderInitiated(msg.sender), "Error: Provider is not yet initiated"); @@ -92,7 +98,7 @@ contract Registry is Destructible, RegistryInterface, Upgradable { } // Gets provider data - function getProviderParameter(address provider, bytes32 key) public view returns (bytes){ + function getProviderParameter(address provider, bytes32 key) public view returns (bytes memory){ // Provider must be initiated require(isProviderInitiated(provider), "Error: Provider is not yet initiated"); require(isProviderParamInitialized(provider, key), "Error: Provider Parameter is not yet initialized"); @@ -100,14 +106,14 @@ contract Registry is Destructible, RegistryInterface, Upgradable { } // Gets keys of all provider params - function getAllProviderParams(address provider) public view returns (bytes32[]){ + function getAllProviderParams(address provider) public view returns (bytes32[] memory){ // Provider must be initiated require(isProviderInitiated(provider), "Error: Provider is not yet initiated"); return db.getBytesArray(keccak256(abi.encodePacked('oracles', provider, 'providerParams'))); } // Set endpoint specific parameters for a given endpoint - function setEndpointParams(bytes32 endpoint, bytes32[] endpointParams) public { + function setEndpointParams(bytes32 endpoint, bytes32[] memory endpointParams) public { // Provider must be initiated require(isProviderInitiated(msg.sender), "Error: Provider is not yet initialized"); // Can't set endpoint params on an unset provider @@ -160,7 +166,7 @@ contract Registry is Destructible, RegistryInterface, Upgradable { ) public view - returns (int[]) + returns (int[] memory) { require(!getCurveUnset(provider, endpoint), "Error: Curve is not yet set"); return db.getIntArray(keccak256(abi.encodePacked('oracles', provider, 'curves', endpoint))); @@ -190,18 +196,19 @@ contract Registry is Destructible, RegistryInterface, Upgradable { } /// @dev get the endpoints of a provider - function getProviderEndpoints(address provider) public view returns (bytes32[]) { + function getProviderEndpoints(address provider) public view returns (bytes32[] memory) { return db.getBytesArray(keccak256(abi.encodePacked("oracles", provider, "endpoints"))); } /// @dev get all endpoint params - function getEndpointParams(address provider, bytes32 endpoint) public view returns (bytes32[]) { + function getEndpointParams(address provider, bytes32 endpoint) public view returns (bytes32[] memory) { 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'))); + return address(db); } function getCurveUnset(address provider, bytes32 endpoint) public view returns (bool) { @@ -214,7 +221,7 @@ contract Registry is Destructible, RegistryInterface, Upgradable { } /// @dev get all oracle addresses - function getAllOracles() external view returns (address[]) { + function getAllOracles() external view returns (address[] memory) { return db.getAddressArray(keccak256(abi.encodePacked('oracleIndex'))); } @@ -236,7 +243,7 @@ contract Registry is Destructible, RegistryInterface, Upgradable { function setCurve( address provider, bytes32 endpoint, - int[] curve + int[] memory curve ) private { diff --git a/contracts/platform/registry/RegistryInterface.sol b/contracts/platform/registry/RegistryInterface.sol old mode 100644 new mode 100755 index 3f434ac..9fb5e59 --- a/contracts/platform/registry/RegistryInterface.sol +++ b/contracts/platform/registry/RegistryInterface.sol @@ -1,21 +1,21 @@ -pragma solidity ^0.4.24; +pragma solidity ^0.5.0; contract RegistryInterface { function initiateProvider(uint256, bytes32) public returns (bool); - function initiateProviderCurve(bytes32, int256[], address) public returns (bool); - function setEndpointParams(bytes32, bytes32[]) public; - function getEndpointParams(address, bytes32) public view returns (bytes32[]); + function initiateProviderCurve(bytes32, int256[] memory, address) public returns (bool); + function setEndpointParams(bytes32, bytes32[] memory) public; + function getEndpointParams(address, bytes32) public view returns (bytes32[] memory); function getProviderPublicKey(address) public view returns (uint256); function getProviderTitle(address) public view returns (bytes32); - function setProviderParameter(bytes32, bytes) public; + function setProviderParameter(bytes32, bytes memory) public; function setProviderTitle(bytes32) public; function clearEndpoint(bytes32) public; - function getProviderParameter(address, bytes32) public view returns (bytes); - function getAllProviderParams(address) public view returns (bytes32[]); + function getProviderParameter(address, bytes32) public view returns (bytes memory); + function getAllProviderParams(address) public view returns (bytes32[] memory); function getProviderCurveLength(address, bytes32) public view returns (uint256); - function getProviderCurve(address, bytes32) public view returns (int[]); + function getProviderCurve(address, bytes32) public view returns (int[] memory); function isProviderInitiated(address) public view returns (bool); - function getAllOracles() external view returns (address[]); - function getProviderEndpoints(address) public view returns (bytes32[]); + function getAllOracles() external view returns (address[] memory); + function getProviderEndpoints(address) public view returns (bytes32[] memory); function getEndpointBroker(address, bytes32) public view returns (address); } From 0309ba797e97b43b735367f377f02ad1a44ad44e Mon Sep 17 00:00:00 2001 From: 7alexlin <7inalex@gmail.com> Date: Thu, 20 Jun 2019 13:57:09 -0400 Subject: [PATCH 2/2] Update Destructible.sol --- contracts/lib/lifecycle/Destructible.sol | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contracts/lib/lifecycle/Destructible.sol b/contracts/lib/lifecycle/Destructible.sol index c16b9a2..d520b1f 100755 --- a/contracts/lib/lifecycle/Destructible.sol +++ b/contracts/lib/lifecycle/Destructible.sol @@ -2,6 +2,10 @@ pragma solidity ^0.5.0; import "../ownership/Ownable.sol"; + +//was not compiling with selfdestruct(owner) added a require and changed parameter from owner to msg.sender + + contract Destructible is Ownable { function selfDestruct() public onlyOwner { require(owner == msg.sender);