From f6abf8255a676c8e64a5befdafc1723d0a91bf8c Mon Sep 17 00:00:00 2001 From: echo Date: Thu, 22 Apr 2021 20:57:16 +0800 Subject: [PATCH 01/32] change constant range to storage --- contracts/LandBaseV2.sol | 242 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 242 insertions(+) create mode 100644 contracts/LandBaseV2.sol diff --git a/contracts/LandBaseV2.sol b/contracts/LandBaseV2.sol new file mode 100644 index 0000000..0df9ad0 --- /dev/null +++ b/contracts/LandBaseV2.sol @@ -0,0 +1,242 @@ +pragma solidity ^0.4.24; + +import "./interfaces/ILandBase.sol"; +import "openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; +import "@evolutionland/common/contracts/interfaces/IObjectOwnership.sol"; +import "@evolutionland/common/contracts/interfaces/ITokenLocation.sol"; +import "@evolutionland/common/contracts/interfaces/ISettingsRegistry.sol"; +import "@evolutionland/common/contracts/DSAuth.sol"; +import "@evolutionland/common/contracts/SettingIds.sol"; +import "@evolutionland/common/contracts/LocationCoder.sol"; + +contract LandBaseV2 is DSAuth, ILandBase, SettingIds { + using LocationCoder for *; + + uint256 constant internal RESERVED = uint256(1); + uint256 constant internal SPECIAL = uint256(2); + uint256 constant internal HASBOX = uint256(4); + + uint256 constant internal CLEAR_RATE_HIGH = 0x000000000000000000000000000000000000000000000000000000000000ffff; + + struct LandAttr { + uint256 resourceRateAttr; + uint256 mask; + } + + bool private singletonLock = false; + + ISettingsRegistry public registry; + + int256 xLow; + int256 xHigh; + int256 yLow; + int256 yHigh; + + /** + * @dev mapping from resource token address to resource atrribute rate id. + * atrribute rate id starts from 1 to 16, NAN is 0. + * goldrate is 1, woodrate is 2, waterrate is 3, firerate is 4, soilrate is 5 + */ + mapping (address => uint8) public resourceToken2RateAttrId; + + /** + * @dev mapping from token id to land resource atrribute. + */ + mapping (uint256 => LandAttr) public tokenId2LandAttr; + + // mapping from position in map to token id. + mapping (uint256 => uint256) public locationId2TokenId; + + uint256 public lastLandObjectId; + + /* + * Modifiers + */ + modifier singletonLockCall() { + require(!singletonLock, "Only can call once"); + _; + singletonLock = true; + } + + modifier xAtlantisRangeLimit(int _x) { + require(_x >= xLow && _x <= xHigh, "Invalid range."); + _; + } + + modifier yAtlantisRangeLimit(int _y) { + require(_y >= yLow && _y <= yHigh, "Invalid range."); + _; + } + + /** + * @dev Same with constructor, but is used and called by storage proxy as logic contract. + */ + function initializeContract(address _registry, int256 _xLow, int256 _xHigh, int256 _yLow, int256 yHigh) public singletonLockCall { + // Ownable constructor + owner = msg.sender; + emit LogSetOwner(msg.sender); + + registry = ISettingsRegistry(_registry); + + // update attributes. + resourceToken2RateAttrId[registry.addressOf(CONTRACT_GOLD_ERC20_TOKEN)] = 1; + resourceToken2RateAttrId[registry.addressOf(CONTRACT_WOOD_ERC20_TOKEN)] = 2; + resourceToken2RateAttrId[registry.addressOf(CONTRACT_WATER_ERC20_TOKEN)] = 3; + resourceToken2RateAttrId[registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN)] = 4; + resourceToken2RateAttrId[registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN)] = 5; + + xLow = _xlow; + xHigh = _xHigh; + yLow = _yLow; + yHigh = _yHigh; + } + + /* + * @dev assign new land + */ + function assignNewLand( + int _x, int _y, address _beneficiary, uint256 _resourceRateAttr, uint256 _mask + ) public auth xAtlantisRangeLimit(_x) yAtlantisRangeLimit(_y) returns (uint _tokenId) { + + // auto increase object id, start from 1 + lastLandObjectId += 1; + require(lastLandObjectId <= 340282366920938463463374607431768211455, "Can not be stored with 128 bits."); + + _tokenId = IObjectOwnership(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).mintObject(_beneficiary, uint128(lastLandObjectId)); + + // update locations. + uint256 locationId = LocationCoder.encodeLocationIdHM(_x, _y); + require(locationId2TokenId[locationId] == 0, "Land in this position already been mint."); + locationId2TokenId[locationId] = _tokenId; + ITokenLocation(registry.addressOf(CONTRACT_TOKEN_LOCATION)).setTokenLocationHM(_tokenId, _x, _y); + + tokenId2LandAttr[_tokenId].resourceRateAttr = _resourceRateAttr; + tokenId2LandAttr[_tokenId].mask = _mask; + + emit CreatedNewLand(_tokenId, _x, _y, _beneficiary, _resourceRateAttr, _mask); + } + + function assignMultipleLands( + int[] _xs, int[] _ys, address _beneficiary, uint256[] _resourceRateAttrs, uint256[] _masks + ) public auth returns (uint[]){ + require(_xs.length == _ys.length, "Length of xs didn't match length of ys"); + require(_xs.length == _resourceRateAttrs.length, "Length of postions didn't match length of land attributes"); + require(_xs.length == _masks.length, "Length of masks didn't match length of ys"); + + uint[] memory _tokenIds = new uint[](_xs.length); + + for (uint i = 0; i < _xs.length; i++) { + _tokenIds[i] = assignNewLand(_xs[i], _ys[i], _beneficiary, _resourceRateAttrs[i], _masks[i]); + } + + return _tokenIds; + } + + function defineResouceTokenRateAttrId(address _resourceToken, uint8 _attrId) public auth { + require(_attrId > 0 && _attrId <= 16, "Invalid Attr Id."); + + resourceToken2RateAttrId[_resourceToken] = _attrId; + } + + // encode (x,y) to get tokenId + function getTokenIdByLocation(int _x, int _y) public view returns (uint256) { + uint locationId = LocationCoder.encodeLocationIdHM(_x, _y); + return locationId2TokenId[locationId]; + } + + function exists(int _x, int _y) public view returns (bool) { + uint locationId = LocationCoder.encodeLocationIdHM(_x, _y); + uint tokenId = locationId2TokenId[locationId]; + return ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).exists(tokenId); + } + + function ownerOfLand(int _x, int _y) public view returns (address) { + uint locationId = LocationCoder.encodeLocationIdHM(_x, _y); + uint tokenId = locationId2TokenId[locationId]; + return ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(tokenId); + } + + function ownerOfLandMany(int[] _xs, int[] _ys) public view returns (address[]) { + require(_xs.length > 0); + require(_xs.length == _ys.length); + + address[] memory addrs = new address[](_xs.length); + for (uint i = 0; i < _xs.length; i++) { + addrs[i] = ownerOfLand(_xs[i], _ys[i]); + } + + return addrs; + } + + function landOf(address _landholder) public view returns (int[], int[]) { + address objectOwnership = registry.addressOf(CONTRACT_OBJECT_OWNERSHIP); + uint256 length = ERC721(objectOwnership).balanceOf(_landholder); + int[] memory x = new int[](length); + int[] memory y = new int[](length); + + ITokenLocation tokenLocation = ITokenLocation(registry.addressOf(CONTRACT_TOKEN_LOCATION)); + + for(uint i = 0; i < length; i++) { + uint tokenId = ERC721(objectOwnership).tokenOfOwnerByIndex(_landholder, i); + (x[i], y[i]) = tokenLocation.getTokenLocationHM(tokenId); + } + + return (x, y); + } + + function isHasBox(uint256 _landTokenID) public view returns (bool) { + return (tokenId2LandAttr[_landTokenID].mask & HASBOX) != 0; + } + + function isReserved(uint256 _landTokenID) public view returns (bool) { + return (tokenId2LandAttr[_landTokenID].mask & RESERVED) != 0; + } + + function isSpecial(uint256 _landTokenID) public view returns (bool) { + return (tokenId2LandAttr[_landTokenID].mask & SPECIAL) != 0; + } + + function setHasBox(uint _landTokenID, bool _isHasBox) public auth { + if (_isHasBox) { + tokenId2LandAttr[_landTokenID].mask |= HASBOX; + } else { + tokenId2LandAttr[_landTokenID].mask &= ~HASBOX; + } + + emit HasboxSetted(_landTokenID, _isHasBox); + } + + function getResourceRateAttr(uint _landTokenId) public view returns (uint256) { + return tokenId2LandAttr[_landTokenId].resourceRateAttr; + } + + function setResourceRateAttr(uint _landTokenId, uint256 _newResourceRateAttr) public auth { + tokenId2LandAttr[_landTokenId].resourceRateAttr = _newResourceRateAttr; + + emit ChangedReourceRateAttr(_landTokenId, _newResourceRateAttr); + } + + function getFlagMask(uint _landTokenId) public view returns (uint256) { + return tokenId2LandAttr[_landTokenId].mask; + } + + function setFlagMask(uint _landTokenId, uint256 _newFlagMask) public auth { + tokenId2LandAttr[_landTokenId].mask = _newFlagMask; + emit ChangedFlagMask(_landTokenId, _newFlagMask); + } + + function getResourceRate(uint _landTokenId, address _resourceToken) public view returns (uint16) { + require(resourceToken2RateAttrId[_resourceToken] > 0, "Resource token doesn't exist."); + + uint moveRight = (16 * (resourceToken2RateAttrId[_resourceToken] - 1)); + return uint16((tokenId2LandAttr[_landTokenId].resourceRateAttr >> moveRight) & CLEAR_RATE_HIGH); + } + + function setResourceRate(uint _landTokenId, address _resourceToken, uint16 _newResouceRate) public auth { + require(resourceToken2RateAttrId[_resourceToken] > 0, "Reource token doesn't exist."); + uint moveLeft = 16 * (resourceToken2RateAttrId[_resourceToken] - 1); + tokenId2LandAttr[_landTokenId].resourceRateAttr &= (~(CLEAR_RATE_HIGH << moveLeft)); + tokenId2LandAttr[_landTokenId].resourceRateAttr |= (uint256(_newResouceRate) << moveLeft); + emit ModifiedResourceRate(_landTokenId, _resourceToken, _newResouceRate); + } +} From a9e95beb9f08cb74a7bd0205d6442f9ca866fbd7 Mon Sep 17 00:00:00 2001 From: echo Date: Thu, 22 Apr 2021 20:57:41 +0800 Subject: [PATCH 02/32] rm flat --- flat/DeployAndTest.sol | 2209 -------------------------- flat/IItemBar.sol | 31 - flat/ILandBase.sol | 37 - flat/IMetaDataTeller.sol | 31 - flat/IMinerObject.sol | 43 - flat/IMysteriousTreasure.sol | 9 - flat/LandBase.sol | 713 --------- flat/LandBaseAuthority.sol | 23 - flat/LandResource.sol | 1001 ------------ flat/LandResourceAuthority.sol | 20 - flat/LandResourceAuthorityV3.sol | 22 - flat/LandResourceV2.sol | 1001 ------------ flat/LandResourceV3.sol | 1060 ------------ flat/LandResourceV4.sol | 1068 ------------- flat/LandResourceV5.sol | 1979 ----------------------- flat/LandSettingIds.sol | 71 - flat/Migrations.sol | 572 ------- flat/MysteriousTreasure.sol | 440 ----- flat/MysteriousTreasureAuthority.sol | 20 - 19 files changed, 10350 deletions(-) delete mode 100644 flat/DeployAndTest.sol delete mode 100644 flat/IItemBar.sol delete mode 100644 flat/ILandBase.sol delete mode 100644 flat/IMetaDataTeller.sol delete mode 100644 flat/IMinerObject.sol delete mode 100644 flat/IMysteriousTreasure.sol delete mode 100644 flat/LandBase.sol delete mode 100644 flat/LandBaseAuthority.sol delete mode 100644 flat/LandResource.sol delete mode 100644 flat/LandResourceAuthority.sol delete mode 100644 flat/LandResourceAuthorityV3.sol delete mode 100644 flat/LandResourceV2.sol delete mode 100644 flat/LandResourceV3.sol delete mode 100644 flat/LandResourceV4.sol delete mode 100644 flat/LandResourceV5.sol delete mode 100644 flat/LandSettingIds.sol delete mode 100644 flat/Migrations.sol delete mode 100644 flat/MysteriousTreasure.sol delete mode 100644 flat/MysteriousTreasureAuthority.sol diff --git a/flat/DeployAndTest.sol b/flat/DeployAndTest.sol deleted file mode 100644 index 9e9f9c9..0000000 --- a/flat/DeployAndTest.sol +++ /dev/null @@ -1,2209 +0,0 @@ -// Dependency file: openzeppelin-solidity/contracts/ownership/Ownable.sol - -// pragma solidity ^0.4.24; - - -/** - * @title Ownable - * @dev The Ownable contract has an owner address, and provides basic authorization control - * functions, this simplifies the implementation of "user permissions". - */ -contract Ownable { - address public owner; - - - event OwnershipRenounced(address indexed previousOwner); - event OwnershipTransferred( - address indexed previousOwner, - address indexed newOwner - ); - - - /** - * @dev The Ownable constructor sets the original `owner` of the contract to the sender - * account. - */ - constructor() public { - owner = msg.sender; - } - - /** - * @dev Throws if called by any account other than the owner. - */ - modifier onlyOwner() { - require(msg.sender == owner); - _; - } - - /** - * @dev Allows the current owner to relinquish control of the contract. - * @notice Renouncing to ownership will leave the contract without an owner. - * It will not be possible to call the functions with the `onlyOwner` - * modifier anymore. - */ - function renounceOwnership() public onlyOwner { - emit OwnershipRenounced(owner); - owner = address(0); - } - - /** - * @dev Allows the current owner to transfer control of the contract to a newOwner. - * @param _newOwner The address to transfer ownership to. - */ - function transferOwnership(address _newOwner) public onlyOwner { - _transferOwnership(_newOwner); - } - - /** - * @dev Transfers control of the contract to a newOwner. - * @param _newOwner The address to transfer ownership to. - */ - function _transferOwnership(address _newOwner) internal { - require(_newOwner != address(0)); - emit OwnershipTransferred(owner, _newOwner); - owner = _newOwner; - } -} - - -// Dependency file: @evolutionland/common/contracts/interfaces/IInterstellarEncoder.sol - -// pragma solidity ^0.4.24; - -contract IInterstellarEncoder { - uint256 constant CLEAR_HIGH = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff; - - uint256 public constant MAGIC_NUMBER = 42; // Interstellar Encoding Magic Number. - uint256 public constant CHAIN_ID = 1; // Ethereum mainet. - uint256 public constant CURRENT_LAND = 1; // 1 is Atlantis, 0 is NaN. - - enum ObjectClass { - NaN, - LAND, - APOSTLE, - OBJECT_CLASS_COUNT - } - - function registerNewObjectClass(address _objectContract, uint8 objectClass) public; - - function registerNewTokenContract(address _tokenAddress) public; - - function encodeTokenId(address _tokenAddress, uint8 _objectClass, uint128 _objectIndex) public view returns (uint256 _tokenId); - - function encodeTokenIdForObjectContract( - address _tokenAddress, address _objectContract, uint128 _objectId) public view returns (uint256 _tokenId); - - function getContractAddress(uint256 _tokenId) public view returns (address); - - function getObjectId(uint256 _tokenId) public view returns (uint128 _objectId); - - function getObjectClass(uint256 _tokenId) public view returns (uint8); - - function getObjectAddress(uint256 _tokenId) public view returns (address); -} - -// Dependency file: @evolutionland/common/contracts/InterstellarEncoder.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; -// import "@evolutionland/common/contracts/interfaces/IInterstellarEncoder.sol"; - -contract InterstellarEncoder is IInterstellarEncoder, Ownable { - // [magic_number, chain_id, contract_id <2>, origin_chain_id, origin_contract_id<2>, object_class, convert_type, <6>, land, <128>] - mapping(uint16 => address) public contractId2Address; - mapping(address => uint16) public contractAddress2Id; - - mapping(address => uint8) public objectContract2ObjectClass; - - uint16 public lastContractId = 0; - - function encodeTokenId(address _tokenAddress, uint8 _objectClass, uint128 _objectId) public view returns (uint256 _tokenId) { - uint16 contractId = contractAddress2Id[_tokenAddress]; - require(contractAddress2Id[_tokenAddress] > 0, "Contract address does not exist"); - - _tokenId = (MAGIC_NUMBER << 248) + (CHAIN_ID << 240) + (uint256(contractId) << 224) - + (CHAIN_ID << 216) + (uint256(contractId) << 200) + (uint256(_objectClass) << 192) + (CURRENT_LAND << 128) + uint256(_objectId); - } - - function encodeTokenIdForObjectContract( - address _tokenAddress, address _objectContract, uint128 _objectId) public view returns (uint256 _tokenId) { - require (objectContract2ObjectClass[_objectContract] > 0, "Object class for this object contract does not exist."); - - _tokenId = encodeTokenId(_tokenAddress, objectContract2ObjectClass[_objectContract], _objectId); - } - - function registerNewTokenContract(address _tokenAddress) public onlyOwner { - require(contractAddress2Id[_tokenAddress] == 0, "Contract address already exist"); - require(lastContractId < 65535, "Contract Id already reach maximum."); - - lastContractId += 1; - - contractAddress2Id[_tokenAddress] = lastContractId; - contractId2Address[lastContractId] = _tokenAddress; - } - - function registerNewObjectClass(address _objectContract, uint8 objectClass) public onlyOwner { - objectContract2ObjectClass[_objectContract] = objectClass; - } - - function getContractAddress(uint256 _tokenId) public view returns (address) { - return contractId2Address[uint16((_tokenId << 16) >> 240)]; - } - - function getObjectId(uint256 _tokenId) public view returns (uint128 _objectId) { - return uint128(_tokenId & CLEAR_HIGH); - } -} - -// Dependency file: @evolutionland/common/contracts/interfaces/ISettingsRegistry.sol - -// pragma solidity ^0.4.24; - -contract ISettingsRegistry { - enum SettingsValueTypes { NONE, UINT, STRING, ADDRESS, BYTES, BOOL, INT } - - function uintOf(bytes32 _propertyName) public view returns (uint256); - - function stringOf(bytes32 _propertyName) public view returns (string); - - function addressOf(bytes32 _propertyName) public view returns (address); - - function bytesOf(bytes32 _propertyName) public view returns (bytes); - - function boolOf(bytes32 _propertyName) public view returns (bool); - - function intOf(bytes32 _propertyName) public view returns (int); - - function setUintProperty(bytes32 _propertyName, uint _value) public; - - function setStringProperty(bytes32 _propertyName, string _value) public; - - function setAddressProperty(bytes32 _propertyName, address _value) public; - - function setBytesProperty(bytes32 _propertyName, bytes _value) public; - - function setBoolProperty(bytes32 _propertyName, bool _value) public; - - function setIntProperty(bytes32 _propertyName, int _value) public; - - function getValueTypeOf(bytes32 _propertyName) public view returns (uint /* SettingsValueTypes */ ); - - event ChangeProperty(bytes32 indexed _propertyName, uint256 _type); -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IAuthority.sol - -// pragma solidity ^0.4.24; - -contract IAuthority { - function canCall( - address src, address dst, bytes4 sig - ) public view returns (bool); -} - -// Dependency file: @evolutionland/common/contracts/DSAuth.sol - -// pragma solidity ^0.4.24; - -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/IAuthority.sol'; - -contract DSAuthEvents { - event LogSetAuthority (address indexed authority); - event LogSetOwner (address indexed owner); -} - -/** - * @title DSAuth - * @dev The DSAuth contract is reference implement of https://github.com/dapphub/ds-auth - * But in the isAuthorized method, the src from address(this) is remove for safty concern. - */ -contract DSAuth is DSAuthEvents { - IAuthority public authority; - address public owner; - - constructor() public { - owner = msg.sender; - emit LogSetOwner(msg.sender); - } - - function setOwner(address owner_) - public - auth - { - owner = owner_; - emit LogSetOwner(owner); - } - - function setAuthority(IAuthority authority_) - public - auth - { - authority = authority_; - emit LogSetAuthority(authority); - } - - modifier auth { - require(isAuthorized(msg.sender, msg.sig)); - _; - } - - modifier onlyOwner() { - require(msg.sender == owner); - _; - } - - function isAuthorized(address src, bytes4 sig) internal view returns (bool) { - if (src == owner) { - return true; - } else if (authority == IAuthority(0)) { - return false; - } else { - return authority.canCall(src, this, sig); - } - } -} - - -// Dependency file: @evolutionland/common/contracts/SettingsRegistry.sol - -// pragma solidity ^0.4.24; - -// import "@evolutionland/common/contracts/interfaces/ISettingsRegistry.sol"; -// import "@evolutionland/common/contracts/DSAuth.sol"; - -/** - * @title SettingsRegistry - * @dev This contract holds all the settings for updating and querying. - */ -contract SettingsRegistry is ISettingsRegistry, DSAuth { - - mapping(bytes32 => uint256) public uintProperties; - mapping(bytes32 => string) public stringProperties; - mapping(bytes32 => address) public addressProperties; - mapping(bytes32 => bytes) public bytesProperties; - mapping(bytes32 => bool) public boolProperties; - mapping(bytes32 => int256) public intProperties; - - mapping(bytes32 => SettingsValueTypes) public valueTypes; - - function uintOf(bytes32 _propertyName) public view returns (uint256) { - require(valueTypes[_propertyName] == SettingsValueTypes.UINT, "Property type does not match."); - return uintProperties[_propertyName]; - } - - function stringOf(bytes32 _propertyName) public view returns (string) { - require(valueTypes[_propertyName] == SettingsValueTypes.STRING, "Property type does not match."); - return stringProperties[_propertyName]; - } - - function addressOf(bytes32 _propertyName) public view returns (address) { - require(valueTypes[_propertyName] == SettingsValueTypes.ADDRESS, "Property type does not match."); - return addressProperties[_propertyName]; - } - - function bytesOf(bytes32 _propertyName) public view returns (bytes) { - require(valueTypes[_propertyName] == SettingsValueTypes.BYTES, "Property type does not match."); - return bytesProperties[_propertyName]; - } - - function boolOf(bytes32 _propertyName) public view returns (bool) { - require(valueTypes[_propertyName] == SettingsValueTypes.BOOL, "Property type does not match."); - return boolProperties[_propertyName]; - } - - function intOf(bytes32 _propertyName) public view returns (int) { - require(valueTypes[_propertyName] == SettingsValueTypes.INT, "Property type does not match."); - return intProperties[_propertyName]; - } - - function setUintProperty(bytes32 _propertyName, uint _value) public auth { - require( - valueTypes[_propertyName] == SettingsValueTypes.NONE || valueTypes[_propertyName] == SettingsValueTypes.UINT, "Property type does not match."); - uintProperties[_propertyName] = _value; - valueTypes[_propertyName] = SettingsValueTypes.UINT; - - emit ChangeProperty(_propertyName, uint256(SettingsValueTypes.UINT)); - } - - function setStringProperty(bytes32 _propertyName, string _value) public auth { - require( - valueTypes[_propertyName] == SettingsValueTypes.NONE || valueTypes[_propertyName] == SettingsValueTypes.STRING, "Property type does not match."); - stringProperties[_propertyName] = _value; - valueTypes[_propertyName] = SettingsValueTypes.STRING; - - emit ChangeProperty(_propertyName, uint256(SettingsValueTypes.STRING)); - } - - function setAddressProperty(bytes32 _propertyName, address _value) public auth { - require( - valueTypes[_propertyName] == SettingsValueTypes.NONE || valueTypes[_propertyName] == SettingsValueTypes.ADDRESS, "Property type does not match."); - - addressProperties[_propertyName] = _value; - valueTypes[_propertyName] = SettingsValueTypes.ADDRESS; - - emit ChangeProperty(_propertyName, uint256(SettingsValueTypes.ADDRESS)); - } - - function setBytesProperty(bytes32 _propertyName, bytes _value) public auth { - require( - valueTypes[_propertyName] == SettingsValueTypes.NONE || valueTypes[_propertyName] == SettingsValueTypes.BYTES, "Property type does not match."); - - bytesProperties[_propertyName] = _value; - valueTypes[_propertyName] = SettingsValueTypes.BYTES; - - emit ChangeProperty(_propertyName, uint256(SettingsValueTypes.BYTES)); - } - - function setBoolProperty(bytes32 _propertyName, bool _value) public auth { - require( - valueTypes[_propertyName] == SettingsValueTypes.NONE || valueTypes[_propertyName] == SettingsValueTypes.BOOL, "Property type does not match."); - - boolProperties[_propertyName] = _value; - valueTypes[_propertyName] = SettingsValueTypes.BOOL; - - emit ChangeProperty(_propertyName, uint256(SettingsValueTypes.BOOL)); - } - - function setIntProperty(bytes32 _propertyName, int _value) public auth { - require( - valueTypes[_propertyName] == SettingsValueTypes.NONE || valueTypes[_propertyName] == SettingsValueTypes.INT, "Property type does not match."); - - intProperties[_propertyName] = _value; - valueTypes[_propertyName] = SettingsValueTypes.INT; - - emit ChangeProperty(_propertyName, uint256(SettingsValueTypes.INT)); - } - - function getValueTypeOf(bytes32 _propertyName) public view returns (uint256 /* SettingsValueTypes */ ) { - return uint256(valueTypes[_propertyName]); - } - -} - -// Dependency file: @evolutionland/common/contracts/SettingIds.sol - -// pragma solidity ^0.4.24; - -/** - Id definitions for SettingsRegistry.sol - Can be used in conjunction with the settings registry to get properties -*/ -contract SettingIds { - bytes32 public constant CONTRACT_RING_ERC20_TOKEN = "CONTRACT_RING_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_KTON_ERC20_TOKEN = "CONTRACT_KTON_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_GOLD_ERC20_TOKEN = "CONTRACT_GOLD_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_WOOD_ERC20_TOKEN = "CONTRACT_WOOD_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_WATER_ERC20_TOKEN = "CONTRACT_WATER_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_FIRE_ERC20_TOKEN = "CONTRACT_FIRE_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_SOIL_ERC20_TOKEN = "CONTRACT_SOIL_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_OBJECT_OWNERSHIP = "CONTRACT_OBJECT_OWNERSHIP"; - - bytes32 public constant CONTRACT_TOKEN_LOCATION = "CONTRACT_TOKEN_LOCATION"; - - bytes32 public constant CONTRACT_LAND_BASE = "CONTRACT_LAND_BASE"; - - bytes32 public constant CONTRACT_USER_POINTS = "CONTRACT_USER_POINTS"; - - bytes32 public constant CONTRACT_INTERSTELLAR_ENCODER = "CONTRACT_INTERSTELLAR_ENCODER"; - - bytes32 public constant CONTRACT_DIVIDENDS_POOL = "CONTRACT_DIVIDENDS_POOL"; - - bytes32 public constant CONTRACT_TOKEN_USE = "CONTRACT_TOKEN_USE"; - - bytes32 public constant CONTRACT_REVENUE_POOL = "CONTRACT_REVENUE_POOL"; - - bytes32 public constant CONTRACT_ERC721_BRIDGE = "CONTRACT_ERC721_BRIDGE"; - - bytes32 public constant CONTRACT_PET_BASE = "CONTRACT_PET_BASE"; - - // Cut owner takes on each auction, measured in basis points (1/100 of a percent). - // this can be considered as transaction fee. - // Values 0-10,000 map to 0%-100% - // set ownerCut to 4% - // ownerCut = 400; - bytes32 public constant UINT_AUCTION_CUT = "UINT_AUCTION_CUT"; // Denominator is 10000 - - bytes32 public constant UINT_TOKEN_OFFER_CUT = "UINT_TOKEN_OFFER_CUT"; // Denominator is 10000 - - // Cut referer takes on each auction, measured in basis points (1/100 of a percent). - // which cut from transaction fee. - // Values 0-10,000 map to 0%-100% - // set refererCut to 4% - // refererCut = 400; - bytes32 public constant UINT_REFERER_CUT = "UINT_REFERER_CUT"; - - bytes32 public constant CONTRACT_LAND_RESOURCE = "CONTRACT_LAND_RESOURCE"; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/ERC223ReceivingContract.sol - -// pragma solidity ^0.4.23; - - /* - * Contract that is working with ERC223 tokens - * https://github.com/ethereum/EIPs/issues/223 - */ - -/// @title ERC223ReceivingContract - Standard contract implementation for compatibility with ERC223 tokens. -contract ERC223ReceivingContract { - - /// @dev Function that is called when a user or another contract wants to transfer funds. - /// @param _from Transaction initiator, analogue of msg.sender - /// @param _value Number of tokens to transfer. - /// @param _data Data containig a function signature and/or parameters - function tokenFallback(address _from, uint256 _value, bytes _data) public; - -} - - -// Dependency file: @evolutionland/common/contracts/interfaces/TokenController.sol - -// pragma solidity ^0.4.23; - - -/// @dev The token controller contract must implement these functions -contract TokenController { - /// @notice Called when `_owner` sends ether to the MiniMe Token contract - /// @param _owner The address that sent the ether to create tokens - /// @return True if the ether is accepted, false if it throws - function proxyPayment(address _owner, bytes4 sig, bytes data) payable public returns (bool); - - /// @notice Notifies the controller about a token transfer allowing the - /// controller to react if desired - /// @param _from The origin of the transfer - /// @param _to The destination of the transfer - /// @param _amount The amount of the transfer - /// @return False if the controller does not authorize the transfer - function onTransfer(address _from, address _to, uint _amount) public returns (bool); - - /// @notice Notifies the controller about an approval allowing the - /// controller to react if desired - /// @param _owner The address that calls `approve()` - /// @param _spender The spender in the `approve()` call - /// @param _amount The amount in the `approve()` call - /// @return False if the controller does not authorize the approval - function onApprove(address _owner, address _spender, uint _amount) public returns (bool); -} - - -// Dependency file: @evolutionland/common/contracts/interfaces/ApproveAndCallFallBack.sol - -// pragma solidity ^0.4.23; - -contract ApproveAndCallFallBack { - function receiveApproval(address from, uint256 _amount, address _token, bytes _data) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/ERC223.sol - -// pragma solidity ^0.4.23; - -contract ERC223 { - function transfer(address to, uint amount, bytes data) public returns (bool ok); - - function transferFrom(address from, address to, uint256 amount, bytes data) public returns (bool ok); - - event ERC223Transfer(address indexed from, address indexed to, uint amount, bytes data); -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol - -// pragma solidity ^0.4.24; - - -/** - * @title ERC20Basic - * @dev Simpler version of ERC20 interface - * See https://github.com/ethereum/EIPs/issues/179 - */ -contract ERC20Basic { - function totalSupply() public view returns (uint256); - function balanceOf(address _who) public view returns (uint256); - function transfer(address _to, uint256 _value) public returns (bool); - event Transfer(address indexed from, address indexed to, uint256 value); -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC20/ERC20.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol"; - - -/** - * @title ERC20 interface - * @dev see https://github.com/ethereum/EIPs/issues/20 - */ -contract ERC20 is ERC20Basic { - function allowance(address _owner, address _spender) - public view 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 - ); -} - - -// Dependency file: openzeppelin-solidity/contracts/math/SafeMath.sol - -// pragma solidity ^0.4.24; - - -/** - * @title SafeMath - * @dev Math operations with safety checks that throw on error - */ -library SafeMath { - - /** - * @dev Multiplies two numbers, throws on overflow. - */ - function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) { - // Gas optimization: this is cheaper than asserting 'a' not being zero, but the - // benefit is lost if 'b' is also tested. - // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 - if (_a == 0) { - return 0; - } - - c = _a * _b; - assert(c / _a == _b); - return c; - } - - /** - * @dev Integer division of two numbers, truncating the quotient. - */ - function div(uint256 _a, uint256 _b) internal pure returns (uint256) { - // assert(_b > 0); // Solidity automatically throws when dividing by 0 - // uint256 c = _a / _b; - // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold - return _a / _b; - } - - /** - * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). - */ - function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { - assert(_b <= _a); - return _a - _b; - } - - /** - * @dev Adds two numbers, throws on overflow. - */ - function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) { - c = _a + _b; - assert(c >= _a); - return c; - } -} - - -// Dependency file: @evolutionland/common/contracts/StandardERC20Base.sol - -// pragma solidity ^0.4.23; - -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol'; -// import "openzeppelin-solidity/contracts/math/SafeMath.sol"; - -contract StandardERC20Base is ERC20 { - using SafeMath for uint256; - - uint256 _supply; - mapping (address => uint256) _balances; - mapping (address => mapping (address => uint256)) _approvals; - - function totalSupply() public view returns (uint) { - return _supply; - } - function balanceOf(address src) public view returns (uint) { - return _balances[src]; - } - function allowance(address src, address guy) public view returns (uint) { - return _approvals[src][guy]; - } - - function transfer(address dst, uint wad) public returns (bool) { - return transferFrom(msg.sender, dst, wad); - } - - function transferFrom(address src, address dst, uint wad) - public - returns (bool) - { - if (src != msg.sender) { - _approvals[src][msg.sender] = _approvals[src][msg.sender].sub(wad); - } - - _balances[src] = _balances[src].sub(wad); - _balances[dst] = _balances[dst].add(wad); - - emit Transfer(src, dst, wad); - - return true; - } - - function approve(address guy, uint wad) public returns (bool) { - _approvals[msg.sender][guy] = wad; - - emit Approval(msg.sender, guy, wad); - - return true; - } -} - - -// Dependency file: @evolutionland/common/contracts/StandardERC223.sol - -// pragma solidity ^0.4.24; - -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/ERC223ReceivingContract.sol'; -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/TokenController.sol'; -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/ApproveAndCallFallBack.sol'; -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/ERC223.sol'; -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/StandardERC20Base.sol'; -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/DSAuth.sol'; - -// This is a contract for demo and test. -contract StandardERC223 is StandardERC20Base, DSAuth, ERC223 { - event Burn(address indexed burner, uint256 value); - event Mint(address indexed to, uint256 amount); - - bytes32 public symbol; - uint256 public decimals = 18; // standard token precision. override to customize - // Optional token name - bytes32 public name = ""; - - address public controller; - - constructor(bytes32 _symbol) public { - symbol = _symbol; - controller = msg.sender; - } - - function setName(bytes32 name_) public auth { - name = name_; - } - -////////// -// Controller Methods -////////// - /// @notice Changes the controller of the contract - /// @param _newController The new controller of the contract - function changeController(address _newController) public auth { - controller = _newController; - } - - /// @notice Send `_amount` tokens to `_to` from `_from` on the condition it - /// is approved by `_from` - /// @param _from The address holding the tokens being transferred - /// @param _to The address of the recipient - /// @param _amount The amount of tokens to be transferred - /// @return True if the transfer was successful - function transferFrom(address _from, address _to, uint256 _amount - ) public returns (bool success) { - // Alerts the token controller of the transfer - if (isContract(controller)) { - if (!TokenController(controller).onTransfer(_from, _to, _amount)) - revert(); - } - - success = super.transferFrom(_from, _to, _amount); - } - - /* - * ERC 223 - * Added support for the ERC 223 "tokenFallback" method in a "transfer" function with a payload. - */ - function transferFrom(address _from, address _to, uint256 _amount, bytes _data) - public - returns (bool success) - { - // Alerts the token controller of the transfer - if (isContract(controller)) { - if (!TokenController(controller).onTransfer(_from, _to, _amount)) - revert(); - } - - require(super.transferFrom(_from, _to, _amount)); - - if (isContract(_to)) { - ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); - receiver.tokenFallback(_from, _amount, _data); - } - - emit ERC223Transfer(_from, _to, _amount, _data); - - return true; - } - - function issue(address _to, uint256 _amount) public auth { - mint(_to, _amount); - } - - function destroy(address _from, uint256 _amount) public auth { - burn(_from, _amount); - } - - function mint(address _to, uint _amount) public auth { - _supply = _supply.add(_amount); - _balances[_to] = _balances[_to].add(_amount); - emit Mint(_to, _amount); - emit Transfer(address(0), _to, _amount); - } - - function burn(address _who, uint _value) public auth { - require(_value <= _balances[_who]); - // no need to require value <= totalSupply, since that would imply the - // sender's balance is greater than the totalSupply, which *should* be an assertion failure - - _balances[_who] = _balances[_who].sub(_value); - _supply = _supply.sub(_value); - emit Burn(_who, _value); - emit Transfer(_who, address(0), _value); - } - - /* - * ERC 223 - * Added support for the ERC 223 "tokenFallback" method in a "transfer" function with a payload. - * https://github.com/ethereum/EIPs/issues/223 - * function transfer(address _to, uint256 _value, bytes _data) public returns (bool success); - */ - /// @notice Send `_value` tokens to `_to` from `msg.sender` and trigger - /// tokenFallback if sender is a contract. - /// @dev Function that is called when a user or another contract wants to transfer funds. - /// @param _to Address of token receiver. - /// @param _amount Number of tokens to transfer. - /// @param _data Data to be sent to tokenFallback - /// @return Returns success of function call. - function transfer( - address _to, - uint256 _amount, - bytes _data) - public - returns (bool success) - { - return transferFrom(msg.sender, _to, _amount, _data); - } - - /// @notice `msg.sender` approves `_spender` to spend `_amount` tokens on - /// its behalf. This is a modified version of the ERC20 approve function - /// to be a little bit safer - /// @param _spender The address of the account able to transfer the tokens - /// @param _amount The amount of tokens to be approved for transfer - /// @return True if the approval was successful - function approve(address _spender, uint256 _amount) public returns (bool success) { - // Alerts the token controller of the approve function call - if (isContract(controller)) { - if (!TokenController(controller).onApprove(msg.sender, _spender, _amount)) - revert(); - } - - return super.approve(_spender, _amount); - } - - /// @notice `msg.sender` approves `_spender` to send `_amount` tokens on - /// its behalf, and then a function is triggered in the contract that is - /// being approved, `_spender`. This allows users to use their tokens to - /// interact with contracts in one function call instead of two - /// @param _spender The address of the contract able to transfer the tokens - /// @param _amount The amount of tokens to be approved for transfer - /// @return True if the function call was successful - function approveAndCall(address _spender, uint256 _amount, bytes _extraData - ) public returns (bool success) { - if (!approve(_spender, _amount)) revert(); - - ApproveAndCallFallBack(_spender).receiveApproval( - msg.sender, - _amount, - this, - _extraData - ); - - return true; - } - - /// @dev Internal function to determine if an address is a contract - /// @param _addr The address being queried - /// @return True if `_addr` is a contract - function isContract(address _addr) constant internal returns(bool) { - uint size; - if (_addr == 0) return false; - assembly { - size := extcodesize(_addr) - } - return size>0; - } - - /// @notice The fallback function: If the contract's controller has not been - /// set to 0, then the `proxyPayment` method is called which relays the - /// ether and creates tokens as described in the token controller contract - function () public payable { - if (isContract(controller)) { - if (! TokenController(controller).proxyPayment.value(msg.value)(msg.sender, msg.sig, msg.data)) - revert(); - } else { - revert(); - } - } - -////////// -// Safety Methods -////////// - - /// @notice This method can be used by the owner to extract mistakenly - /// sent tokens to this contract. - /// @param _token The address of the token contract that you want to recover - /// set to 0 in case you want to extract ether. - function claimTokens(address _token) public auth { - if (_token == 0x0) { - address(msg.sender).transfer(address(this).balance); - return; - } - - ERC20 token = ERC20(_token); - uint balance = token.balanceOf(this); - token.transfer(address(msg.sender), balance); - - emit ClaimedTokens(_token, address(msg.sender), balance); - } - -//////////////// -// Events -//////////////// - - event ClaimedTokens(address indexed _token, address indexed _controller, uint _amount); -} - -// Dependency file: openzeppelin-solidity/contracts/introspection/ERC165.sol - -// pragma solidity ^0.4.24; - - -/** - * @title ERC165 - * @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md - */ -interface ERC165 { - - /** - * @notice Query if a contract implements an interface - * @param _interfaceId The interface identifier, as specified in ERC-165 - * @dev Interface identification is specified in ERC-165. This function - * uses less than 30,000 gas. - */ - function supportsInterface(bytes4 _interfaceId) - external - view - returns (bool); -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - - -/** - * @title ERC721 Non-Fungible Token Standard basic interface - * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Basic is ERC165 { - - bytes4 internal constant InterfaceId_ERC721 = 0x80ac58cd; - /* - * 0x80ac58cd === - * bytes4(keccak256('balanceOf(address)')) ^ - * bytes4(keccak256('ownerOf(uint256)')) ^ - * bytes4(keccak256('approve(address,uint256)')) ^ - * bytes4(keccak256('getApproved(uint256)')) ^ - * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ - * bytes4(keccak256('isApprovedForAll(address,address)')) ^ - * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ - * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ - * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) - */ - - bytes4 internal constant InterfaceId_ERC721Exists = 0x4f558e79; - /* - * 0x4f558e79 === - * bytes4(keccak256('exists(uint256)')) - */ - - bytes4 internal constant InterfaceId_ERC721Enumerable = 0x780e9d63; - /** - * 0x780e9d63 === - * bytes4(keccak256('totalSupply()')) ^ - * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) ^ - * bytes4(keccak256('tokenByIndex(uint256)')) - */ - - bytes4 internal constant InterfaceId_ERC721Metadata = 0x5b5e139f; - /** - * 0x5b5e139f === - * bytes4(keccak256('name()')) ^ - * bytes4(keccak256('symbol()')) ^ - * bytes4(keccak256('tokenURI(uint256)')) - */ - - event Transfer( - address indexed _from, - address indexed _to, - uint256 indexed _tokenId - ); - event Approval( - address indexed _owner, - address indexed _approved, - uint256 indexed _tokenId - ); - event ApprovalForAll( - address indexed _owner, - address indexed _operator, - bool _approved - ); - - function balanceOf(address _owner) public view returns (uint256 _balance); - function ownerOf(uint256 _tokenId) public view returns (address _owner); - function exists(uint256 _tokenId) public view returns (bool _exists); - - function approve(address _to, uint256 _tokenId) public; - function getApproved(uint256 _tokenId) - public view returns (address _operator); - - function setApprovalForAll(address _operator, bool _approved) public; - function isApprovedForAll(address _owner, address _operator) - public view returns (bool); - - function transferFrom(address _from, address _to, uint256 _tokenId) public; - function safeTransferFrom(address _from, address _to, uint256 _tokenId) - public; - - function safeTransferFrom( - address _from, - address _to, - uint256 _tokenId, - bytes _data - ) - public; -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol"; - - -/** - * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Enumerable is ERC721Basic { - function totalSupply() public view returns (uint256); - function tokenOfOwnerByIndex( - address _owner, - uint256 _index - ) - public - view - returns (uint256 _tokenId); - - function tokenByIndex(uint256 _index) public view returns (uint256); -} - - -/** - * @title ERC-721 Non-Fungible Token Standard, optional metadata extension - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Metadata is ERC721Basic { - function name() external view returns (string _name); - function symbol() external view returns (string _symbol); - function tokenURI(uint256 _tokenId) public view returns (string); -} - - -/** - * @title ERC-721 Non-Fungible Token Standard, full implementation interface - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721 is ERC721Basic, ERC721Enumerable, ERC721Metadata { -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721Receiver.sol - -// pragma solidity ^0.4.24; - - -/** - * @title ERC721 token receiver interface - * @dev Interface for any contract that wants to support safeTransfers - * from ERC721 asset contracts. - */ -contract ERC721Receiver { - /** - * @dev Magic value to be returned upon successful reception of an NFT - * Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`, - * which can be also obtained as `ERC721Receiver(0).onERC721Received.selector` - */ - bytes4 internal constant ERC721_RECEIVED = 0x150b7a02; - - /** - * @notice Handle the receipt of an NFT - * @dev The ERC721 smart contract calls this function on the recipient - * after a `safetransfer`. This function MAY throw to revert and reject the - * transfer. Return of other than the magic value MUST result in the - * transaction being reverted. - * Note: the contract address is always the message sender. - * @param _operator The address which called `safeTransferFrom` function - * @param _from The address which previously owned the token - * @param _tokenId The NFT identifier which is being transferred - * @param _data Additional data with no specified format - * @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` - */ - function onERC721Received( - address _operator, - address _from, - uint256 _tokenId, - bytes _data - ) - public - returns(bytes4); -} - - -// Dependency file: openzeppelin-solidity/contracts/AddressUtils.sol - -// pragma solidity ^0.4.24; - - -/** - * Utility library of inline functions on addresses - */ -library AddressUtils { - - /** - * Returns whether the target address is a contract - * @dev This function will return false if invoked during the constructor of a contract, - * as the code is not actually created until after the constructor finishes. - * @param _addr address to check - * @return whether the target address is a contract - */ - function isContract(address _addr) internal view returns (bool) { - uint256 size; - // XXX Currently there is no better way to check if there is a contract in an address - // than to check the size of the code at that address. - // See https://ethereum.stackexchange.com/a/14016/36603 - // for more details about how this works. - // TODO Check this again before the Serenity release, because all addresses will be - // contracts then. - // solium-disable-next-line security/no-inline-assembly - assembly { size := extcodesize(_addr) } - return size > 0; - } - -} - - -// Dependency file: openzeppelin-solidity/contracts/introspection/SupportsInterfaceWithLookup.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - - -/** - * @title SupportsInterfaceWithLookup - * @author Matt Condon (@shrugs) - * @dev Implements ERC165 using a lookup table. - */ -contract SupportsInterfaceWithLookup is ERC165 { - - bytes4 public constant InterfaceId_ERC165 = 0x01ffc9a7; - /** - * 0x01ffc9a7 === - * bytes4(keccak256('supportsInterface(bytes4)')) - */ - - /** - * @dev a mapping of interface id to whether or not it's supported - */ - mapping(bytes4 => bool) internal supportedInterfaces; - - /** - * @dev A contract implementing SupportsInterfaceWithLookup - * implement ERC165 itself - */ - constructor() - public - { - _registerInterface(InterfaceId_ERC165); - } - - /** - * @dev implement supportsInterface(bytes4) using a lookup table - */ - function supportsInterface(bytes4 _interfaceId) - external - view - returns (bool) - { - return supportedInterfaces[_interfaceId]; - } - - /** - * @dev private method for registering an interface - */ - function _registerInterface(bytes4 _interfaceId) - internal - { - require(_interfaceId != 0xffffffff); - supportedInterfaces[_interfaceId] = true; - } -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721BasicToken.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol"; -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721Receiver.sol"; -// import "openzeppelin-solidity/contracts/math/SafeMath.sol"; -// import "openzeppelin-solidity/contracts/AddressUtils.sol"; -// import "openzeppelin-solidity/contracts/introspection/SupportsInterfaceWithLookup.sol"; - - -/** - * @title ERC721 Non-Fungible Token Standard basic implementation - * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721BasicToken is SupportsInterfaceWithLookup, ERC721Basic { - - using SafeMath for uint256; - using AddressUtils for address; - - // Equals to `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` - // which can be also obtained as `ERC721Receiver(0).onERC721Received.selector` - bytes4 private constant ERC721_RECEIVED = 0x150b7a02; - - // Mapping from token ID to owner - mapping (uint256 => address) internal tokenOwner; - - // Mapping from token ID to approved address - mapping (uint256 => address) internal tokenApprovals; - - // Mapping from owner to number of owned token - mapping (address => uint256) internal ownedTokensCount; - - // Mapping from owner to operator approvals - mapping (address => mapping (address => bool)) internal operatorApprovals; - - constructor() - public - { - // register the supported interfaces to conform to ERC721 via ERC165 - _registerInterface(InterfaceId_ERC721); - _registerInterface(InterfaceId_ERC721Exists); - } - - /** - * @dev Gets the balance of the specified address - * @param _owner address to query the balance of - * @return uint256 representing the amount owned by the passed address - */ - function balanceOf(address _owner) public view returns (uint256) { - require(_owner != address(0)); - return ownedTokensCount[_owner]; - } - - /** - * @dev Gets the owner of the specified token ID - * @param _tokenId uint256 ID of the token to query the owner of - * @return owner address currently marked as the owner of the given token ID - */ - function ownerOf(uint256 _tokenId) public view returns (address) { - address owner = tokenOwner[_tokenId]; - require(owner != address(0)); - return owner; - } - - /** - * @dev Returns whether the specified token exists - * @param _tokenId uint256 ID of the token to query the existence of - * @return whether the token exists - */ - function exists(uint256 _tokenId) public view returns (bool) { - address owner = tokenOwner[_tokenId]; - return owner != address(0); - } - - /** - * @dev Approves another address to transfer the given token ID - * The zero address indicates there is no approved address. - * There can only be one approved address per token at a given time. - * Can only be called by the token owner or an approved operator. - * @param _to address to be approved for the given token ID - * @param _tokenId uint256 ID of the token to be approved - */ - function approve(address _to, uint256 _tokenId) public { - address owner = ownerOf(_tokenId); - require(_to != owner); - require(msg.sender == owner || isApprovedForAll(owner, msg.sender)); - - tokenApprovals[_tokenId] = _to; - emit Approval(owner, _to, _tokenId); - } - - /** - * @dev Gets the approved address for a token ID, or zero if no address set - * @param _tokenId uint256 ID of the token to query the approval of - * @return address currently approved for the given token ID - */ - function getApproved(uint256 _tokenId) public view returns (address) { - return tokenApprovals[_tokenId]; - } - - /** - * @dev Sets or unsets the approval of a given operator - * An operator is allowed to transfer all tokens of the sender on their behalf - * @param _to operator address to set the approval - * @param _approved representing the status of the approval to be set - */ - function setApprovalForAll(address _to, bool _approved) public { - require(_to != msg.sender); - operatorApprovals[msg.sender][_to] = _approved; - emit ApprovalForAll(msg.sender, _to, _approved); - } - - /** - * @dev Tells whether an operator is approved by a given owner - * @param _owner owner address which you want to query the approval of - * @param _operator operator address which you want to query the approval of - * @return bool whether the given operator is approved by the given owner - */ - function isApprovedForAll( - address _owner, - address _operator - ) - public - view - returns (bool) - { - return operatorApprovals[_owner][_operator]; - } - - /** - * @dev Transfers the ownership of a given token ID to another address - * Usage of this method is discouraged, use `safeTransferFrom` whenever possible - * Requires the msg sender to be the owner, approved, or operator - * @param _from current owner of the token - * @param _to address to receive the ownership of the given token ID - * @param _tokenId uint256 ID of the token to be transferred - */ - function transferFrom( - address _from, - address _to, - uint256 _tokenId - ) - public - { - require(isApprovedOrOwner(msg.sender, _tokenId)); - require(_from != address(0)); - require(_to != address(0)); - - clearApproval(_from, _tokenId); - removeTokenFrom(_from, _tokenId); - addTokenTo(_to, _tokenId); - - emit Transfer(_from, _to, _tokenId); - } - - /** - * @dev Safely transfers the ownership of a given token ID to another address - * If the target address is a contract, it must implement `onERC721Received`, - * which is called upon a safe transfer, and return the magic value - * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, - * the transfer is reverted. - * - * Requires the msg sender to be the owner, approved, or operator - * @param _from current owner of the token - * @param _to address to receive the ownership of the given token ID - * @param _tokenId uint256 ID of the token to be transferred - */ - function safeTransferFrom( - address _from, - address _to, - uint256 _tokenId - ) - public - { - // solium-disable-next-line arg-overflow - safeTransferFrom(_from, _to, _tokenId, ""); - } - - /** - * @dev Safely transfers the ownership of a given token ID to another address - * If the target address is a contract, it must implement `onERC721Received`, - * which is called upon a safe transfer, and return the magic value - * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, - * the transfer is reverted. - * Requires the msg sender to be the owner, approved, or operator - * @param _from current owner of the token - * @param _to address to receive the ownership of the given token ID - * @param _tokenId uint256 ID of the token to be transferred - * @param _data bytes data to send along with a safe transfer check - */ - function safeTransferFrom( - address _from, - address _to, - uint256 _tokenId, - bytes _data - ) - public - { - transferFrom(_from, _to, _tokenId); - // solium-disable-next-line arg-overflow - require(checkAndCallSafeTransfer(_from, _to, _tokenId, _data)); - } - - /** - * @dev Returns whether the given spender can transfer a given token ID - * @param _spender address of the spender to query - * @param _tokenId uint256 ID of the token to be transferred - * @return bool whether the msg.sender is approved for the given token ID, - * is an operator of the owner, or is the owner of the token - */ - function isApprovedOrOwner( - address _spender, - uint256 _tokenId - ) - internal - view - returns (bool) - { - address owner = ownerOf(_tokenId); - // Disable solium check because of - // https://github.com/duaraghav8/Solium/issues/175 - // solium-disable-next-line operator-whitespace - return ( - _spender == owner || - getApproved(_tokenId) == _spender || - isApprovedForAll(owner, _spender) - ); - } - - /** - * @dev Internal function to mint a new token - * Reverts if the given token ID already exists - * @param _to The address that will own the minted token - * @param _tokenId uint256 ID of the token to be minted by the msg.sender - */ - function _mint(address _to, uint256 _tokenId) internal { - require(_to != address(0)); - addTokenTo(_to, _tokenId); - emit Transfer(address(0), _to, _tokenId); - } - - /** - * @dev Internal function to burn a specific token - * Reverts if the token does not exist - * @param _tokenId uint256 ID of the token being burned by the msg.sender - */ - function _burn(address _owner, uint256 _tokenId) internal { - clearApproval(_owner, _tokenId); - removeTokenFrom(_owner, _tokenId); - emit Transfer(_owner, address(0), _tokenId); - } - - /** - * @dev Internal function to clear current approval of a given token ID - * Reverts if the given address is not indeed the owner of the token - * @param _owner owner of the token - * @param _tokenId uint256 ID of the token to be transferred - */ - function clearApproval(address _owner, uint256 _tokenId) internal { - require(ownerOf(_tokenId) == _owner); - if (tokenApprovals[_tokenId] != address(0)) { - tokenApprovals[_tokenId] = address(0); - } - } - - /** - * @dev Internal function to add a token ID to the list of a given address - * @param _to address representing the new owner of the given token ID - * @param _tokenId uint256 ID of the token to be added to the tokens list of the given address - */ - function addTokenTo(address _to, uint256 _tokenId) internal { - require(tokenOwner[_tokenId] == address(0)); - tokenOwner[_tokenId] = _to; - ownedTokensCount[_to] = ownedTokensCount[_to].add(1); - } - - /** - * @dev Internal function to remove a token ID from the list of a given address - * @param _from address representing the previous owner of the given token ID - * @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address - */ - function removeTokenFrom(address _from, uint256 _tokenId) internal { - require(ownerOf(_tokenId) == _from); - ownedTokensCount[_from] = ownedTokensCount[_from].sub(1); - tokenOwner[_tokenId] = address(0); - } - - /** - * @dev Internal function to invoke `onERC721Received` on a target address - * The call is not executed if the target address is not a contract - * @param _from address representing the previous owner of the given token ID - * @param _to target address that will receive the tokens - * @param _tokenId uint256 ID of the token to be transferred - * @param _data bytes optional data to send along with the call - * @return whether the call correctly returned the expected magic value - */ - function checkAndCallSafeTransfer( - address _from, - address _to, - uint256 _tokenId, - bytes _data - ) - internal - returns (bool) - { - if (!_to.isContract()) { - return true; - } - bytes4 retval = ERC721Receiver(_to).onERC721Received( - msg.sender, _from, _tokenId, _data); - return (retval == ERC721_RECEIVED); - } -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721Token.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721BasicToken.sol"; -// import "openzeppelin-solidity/contracts/introspection/SupportsInterfaceWithLookup.sol"; - - -/** - * @title Full ERC721 Token - * This implementation includes all the required and some optional functionality of the ERC721 standard - * Moreover, it includes approve all functionality using operator terminology - * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Token is SupportsInterfaceWithLookup, ERC721BasicToken, ERC721 { - - // Token name - string internal name_; - - // Token symbol - string internal symbol_; - - // Mapping from owner to list of owned token IDs - mapping(address => uint256[]) internal ownedTokens; - - // Mapping from token ID to index of the owner tokens list - mapping(uint256 => uint256) internal ownedTokensIndex; - - // Array with all token ids, used for enumeration - uint256[] internal allTokens; - - // Mapping from token id to position in the allTokens array - mapping(uint256 => uint256) internal allTokensIndex; - - // Optional mapping for token URIs - mapping(uint256 => string) internal tokenURIs; - - /** - * @dev Constructor function - */ - constructor(string _name, string _symbol) public { - name_ = _name; - symbol_ = _symbol; - - // register the supported interfaces to conform to ERC721 via ERC165 - _registerInterface(InterfaceId_ERC721Enumerable); - _registerInterface(InterfaceId_ERC721Metadata); - } - - /** - * @dev Gets the token name - * @return string representing the token name - */ - function name() external view returns (string) { - return name_; - } - - /** - * @dev Gets the token symbol - * @return string representing the token symbol - */ - function symbol() external view returns (string) { - return symbol_; - } - - /** - * @dev Returns an URI for a given token ID - * Throws if the token ID does not exist. May return an empty string. - * @param _tokenId uint256 ID of the token to query - */ - function tokenURI(uint256 _tokenId) public view returns (string) { - require(exists(_tokenId)); - return tokenURIs[_tokenId]; - } - - /** - * @dev Gets the token ID at a given index of the tokens list of the requested owner - * @param _owner address owning the tokens list to be accessed - * @param _index uint256 representing the index to be accessed of the requested tokens list - * @return uint256 token ID at the given index of the tokens list owned by the requested address - */ - function tokenOfOwnerByIndex( - address _owner, - uint256 _index - ) - public - view - returns (uint256) - { - require(_index < balanceOf(_owner)); - return ownedTokens[_owner][_index]; - } - - /** - * @dev Gets the total amount of tokens stored by the contract - * @return uint256 representing the total amount of tokens - */ - function totalSupply() public view returns (uint256) { - return allTokens.length; - } - - /** - * @dev Gets the token ID at a given index of all the tokens in this contract - * Reverts if the index is greater or equal to the total number of tokens - * @param _index uint256 representing the index to be accessed of the tokens list - * @return uint256 token ID at the given index of the tokens list - */ - function tokenByIndex(uint256 _index) public view returns (uint256) { - require(_index < totalSupply()); - return allTokens[_index]; - } - - /** - * @dev Internal function to set the token URI for a given token - * Reverts if the token ID does not exist - * @param _tokenId uint256 ID of the token to set its URI - * @param _uri string URI to assign - */ - function _setTokenURI(uint256 _tokenId, string _uri) internal { - require(exists(_tokenId)); - tokenURIs[_tokenId] = _uri; - } - - /** - * @dev Internal function to add a token ID to the list of a given address - * @param _to address representing the new owner of the given token ID - * @param _tokenId uint256 ID of the token to be added to the tokens list of the given address - */ - function addTokenTo(address _to, uint256 _tokenId) internal { - super.addTokenTo(_to, _tokenId); - uint256 length = ownedTokens[_to].length; - ownedTokens[_to].push(_tokenId); - ownedTokensIndex[_tokenId] = length; - } - - /** - * @dev Internal function to remove a token ID from the list of a given address - * @param _from address representing the previous owner of the given token ID - * @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address - */ - function removeTokenFrom(address _from, uint256 _tokenId) internal { - super.removeTokenFrom(_from, _tokenId); - - // To prevent a gap in the array, we store the last token in the index of the token to delete, and - // then delete the last slot. - uint256 tokenIndex = ownedTokensIndex[_tokenId]; - uint256 lastTokenIndex = ownedTokens[_from].length.sub(1); - uint256 lastToken = ownedTokens[_from][lastTokenIndex]; - - ownedTokens[_from][tokenIndex] = lastToken; - // This also deletes the contents at the last position of the array - ownedTokens[_from].length--; - - // Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to - // be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping - // the lastToken to the first position, and then dropping the element placed in the last position of the list - - ownedTokensIndex[_tokenId] = 0; - ownedTokensIndex[lastToken] = tokenIndex; - } - - /** - * @dev Internal function to mint a new token - * Reverts if the given token ID already exists - * @param _to address the beneficiary that will own the minted token - * @param _tokenId uint256 ID of the token to be minted by the msg.sender - */ - function _mint(address _to, uint256 _tokenId) internal { - super._mint(_to, _tokenId); - - allTokensIndex[_tokenId] = allTokens.length; - allTokens.push(_tokenId); - } - - /** - * @dev Internal function to burn a specific token - * Reverts if the token does not exist - * @param _owner owner of the token to burn - * @param _tokenId uint256 ID of the token being burned by the msg.sender - */ - function _burn(address _owner, uint256 _tokenId) internal { - super._burn(_owner, _tokenId); - - // Clear metadata (if any) - if (bytes(tokenURIs[_tokenId]).length != 0) { - delete tokenURIs[_tokenId]; - } - - // Reorg all tokens array - uint256 tokenIndex = allTokensIndex[_tokenId]; - uint256 lastTokenIndex = allTokens.length.sub(1); - uint256 lastToken = allTokens[lastTokenIndex]; - - allTokens[tokenIndex] = lastToken; - allTokens[lastTokenIndex] = 0; - - allTokens.length--; - allTokensIndex[_tokenId] = 0; - allTokensIndex[lastToken] = tokenIndex; - } - -} - - -// Dependency file: @evolutionland/common/contracts/ObjectOwnership.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/ownership/Ownable.sol"; -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721Token.sol"; -// import "@evolutionland/common/contracts/interfaces/IInterstellarEncoder.sol"; -// import "@evolutionland/common/contracts/interfaces/ISettingsRegistry.sol"; -// import "@evolutionland/common/contracts/DSAuth.sol"; -// import "@evolutionland/common/contracts/SettingIds.sol"; - -contract ObjectOwnership is ERC721Token("Evolution Land Objects","EVO"), DSAuth, SettingIds { - ISettingsRegistry public registry; - - bool private singletonLock = false; - - /* - * Modifiers - */ - modifier singletonLockCall() { - require(!singletonLock, "Only can call once"); - _; - singletonLock = true; - } - - /** - * @dev Atlantis's constructor - */ - constructor () public { - // initializeContract(); - } - - /** - * @dev Same with constructor, but is used and called by storage proxy as logic contract. - */ - function initializeContract(address _registry) public singletonLockCall { - // Ownable constructor - owner = msg.sender; - emit LogSetOwner(msg.sender); - - // SupportsInterfaceWithLookup constructor - _registerInterface(InterfaceId_ERC165); - - // ERC721BasicToken constructor - _registerInterface(InterfaceId_ERC721); - _registerInterface(InterfaceId_ERC721Exists); - - // ERC721Token constructor - name_ = "Evolution Land Objects"; - symbol_ = "EVO"; // Evolution Land Objects - // register the supported interfaces to conform to ERC721 via ERC165 - _registerInterface(InterfaceId_ERC721Enumerable); - _registerInterface(InterfaceId_ERC721Metadata); - - registry = ISettingsRegistry(_registry); - } - - function mintObject(address _to, uint128 _objectId) public auth returns (uint256 _tokenId) { - address interstellarEncoder = registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER); - - _tokenId = IInterstellarEncoder(interstellarEncoder).encodeTokenIdForObjectContract( - address(this), msg.sender, _objectId); - super._mint(_to, _tokenId); - } - - function burnObject(address _to, uint128 _objectId) public auth returns (uint256 _tokenId) { - address interstellarEncoder = registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER); - - _tokenId = IInterstellarEncoder(interstellarEncoder).encodeTokenIdForObjectContract( - address(this), msg.sender, _objectId); - super._burn(_to, _tokenId); - } - - function mint(address _to, uint256 _tokenId) public auth { - super._mint(_to, _tokenId); - } - - function burn(address _to, uint256 _tokenId) public auth { - super._burn(_to, _tokenId); - } - - //@dev user invoke approveAndCall to create auction - //@param _to - address of auction contractß - function approveAndCall( - address _to, - uint _tokenId, - bytes _extraData - ) public { - // set _to to the auction contract - approve(_to, _tokenId); - - if(!_to.call( - bytes4(keccak256("receiveApproval(address,uint256,bytes)")), abi.encode(msg.sender, _tokenId, _extraData) - )) { - revert(); - } - } -} - - -// Dependency file: @evolutionland/upgraeability-using-unstructured-storage/contracts/Proxy.sol - -// pragma solidity ^0.4.21; - -/** - * @title Proxy - * @dev Gives the possibility to delegate any call to a foreign implementation. - */ -contract Proxy { - /** - * @dev Tells the address of the implementation where every call will be delegated. - * @return address of the implementation to which it will be delegated - */ - function implementation() public view returns (address); - - /** - * @dev Fallback function allowing to perform a delegatecall to the given implementation. - * This function will return whatever the implementation call returns - */ - function () payable public { - address _impl = implementation(); - require(_impl != address(0)); - - assembly { - let ptr := mload(0x40) - calldatacopy(ptr, 0, calldatasize) - let result := delegatecall(gas, _impl, ptr, calldatasize, 0, 0) - let size := returndatasize - returndatacopy(ptr, 0, size) - - switch result - case 0 { revert(ptr, size) } - default { return(ptr, size) } - } - } -} - - -// Dependency file: @evolutionland/upgraeability-using-unstructured-storage/contracts/UpgradeabilityProxy.sol - -// pragma solidity ^0.4.21; - -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/upgraeability-using-unstructured-storage/contracts/Proxy.sol'; - -/** - * @title UpgradeabilityProxy - * @dev This contract represents a proxy where the implementation address to which it will delegate can be upgraded - */ -contract UpgradeabilityProxy is Proxy { - /** - * @dev This event will be emitted every time the implementation gets upgraded - * @param implementation representing the address of the upgraded implementation - */ - event Upgraded(address indexed implementation); - - // Storage position of the address of the current implementation - bytes32 private constant implementationPosition = keccak256("org.zeppelinos.proxy.implementation"); - - /** - * @dev Constructor function - */ - function UpgradeabilityProxy() public {} - - /** - * @dev Tells the address of the current implementation - * @return address of the current implementation - */ - function implementation() public view returns (address impl) { - bytes32 position = implementationPosition; - assembly { - impl := sload(position) - } - } - - /** - * @dev Sets the address of the current implementation - * @param newImplementation address representing the new implementation to be set - */ - function setImplementation(address newImplementation) internal { - bytes32 position = implementationPosition; - assembly { - sstore(position, newImplementation) - } - } - - /** - * @dev Upgrades the implementation address - * @param newImplementation representing the address of the new implementation to be set - */ - function _upgradeTo(address newImplementation) internal { - address currentImplementation = implementation(); - require(currentImplementation != newImplementation); - setImplementation(newImplementation); - emit Upgraded(newImplementation); - } -} - - -// Dependency file: @evolutionland/upgraeability-using-unstructured-storage/contracts/OwnedUpgradeabilityProxy.sol - -// pragma solidity ^0.4.21; - -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/upgraeability-using-unstructured-storage/contracts/UpgradeabilityProxy.sol'; - -/** - * @title OwnedUpgradeabilityProxy - * @dev This contract combines an upgradeability proxy with basic authorization control functionalities - */ -contract OwnedUpgradeabilityProxy is UpgradeabilityProxy { - /** - * @dev Event to show ownership has been transferred - * @param previousOwner representing the address of the previous owner - * @param newOwner representing the address of the new owner - */ - event ProxyOwnershipTransferred(address previousOwner, address newOwner); - - // Storage position of the owner of the contract - bytes32 private constant proxyOwnerPosition = keccak256("org.zeppelinos.proxy.owner"); - - /** - * @dev the constructor sets the original owner of the contract to the sender account. - */ - function OwnedUpgradeabilityProxy() public { - setUpgradeabilityOwner(msg.sender); - } - - /** - * @dev Throws if called by any account other than the owner. - */ - modifier onlyProxyOwner() { - require(msg.sender == proxyOwner()); - _; - } - - /** - * @dev Tells the address of the owner - * @return the address of the owner - */ - function proxyOwner() public view returns (address owner) { - bytes32 position = proxyOwnerPosition; - assembly { - owner := sload(position) - } - } - - /** - * @dev Sets the address of the owner - */ - function setUpgradeabilityOwner(address newProxyOwner) internal { - bytes32 position = proxyOwnerPosition; - assembly { - sstore(position, newProxyOwner) - } - } - - /** - * @dev Allows the current owner to transfer control of the contract to a newOwner. - * @param newOwner The address to transfer ownership to. - */ - function transferProxyOwnership(address newOwner) public onlyProxyOwner { - require(newOwner != address(0)); - emit ProxyOwnershipTransferred(proxyOwner(), newOwner); - setUpgradeabilityOwner(newOwner); - } - - /** - * @dev Allows the proxy owner to upgrade the current version of the proxy. - * @param implementation representing the address of the new implementation to be set. - */ - function upgradeTo(address implementation) public onlyProxyOwner { - _upgradeTo(implementation); - } - - /** - * @dev Allows the proxy owner to upgrade the current version of the proxy and call the new implementation - * to initialize whatever is needed through a low level call. - * @param implementation representing the address of the new implementation to be set. - * @param data represents the msg.data to bet sent in the low level call. This parameter may include the function - * signature of the implementation to be called with the needed payload - */ - function upgradeToAndCall(address implementation, bytes data) payable public onlyProxyOwner { - upgradeTo(implementation); - require(this.call.value(msg.value)(data)); - } -} - - -// Dependency file: @evolutionland/common/contracts/interfaces/ITokenLocation.sol - -// pragma solidity ^0.4.24; - -contract ITokenLocation { - - function hasLocation(uint256 _tokenId) public view returns (bool); - - function getTokenLocation(uint256 _tokenId) public view returns (int, int); - - function setTokenLocation(uint256 _tokenId, int _x, int _y) public; - - function getTokenLocationHM(uint256 _tokenId) public view returns (int, int); - - function setTokenLocationHM(uint256 _tokenId, int _x, int _y) public; -} - -// Dependency file: @evolutionland/common/contracts/LocationCoder.sol - -// pragma solidity ^0.4.24; - -library LocationCoder { - // the allocation of the [x, y, z] is [0<1>, x<21>, y<21>, z<21>] - uint256 constant CLEAR_YZ = 0x0fffffffffffffffffffff000000000000000000000000000000000000000000; - uint256 constant CLEAR_XZ = 0x0000000000000000000000fffffffffffffffffffff000000000000000000000; - uint256 constant CLEAR_XY = 0x0000000000000000000000000000000000000000000fffffffffffffffffffff; - - uint256 constant NOT_ZERO = 0x1000000000000000000000000000000000000000000000000000000000000000; - uint256 constant APPEND_HIGH = 0xfffffffffffffffffffffffffffffffffffffffffff000000000000000000000; - - uint256 constant MAX_LOCATION_ID = 0x2000000000000000000000000000000000000000000000000000000000000000; - - int256 constant HMETER_DECIMAL = 10 ** 8; - - // x, y, z should between -2^83 (-9671406556917033397649408) and 2^83 - 1 (9671406556917033397649407). - int256 constant MIN_Location_XYZ = -9671406556917033397649408; - int256 constant MAX_Location_XYZ = 9671406556917033397649407; - // 96714065569170334.50000000 - int256 constant MAX_HM_DECIMAL = 9671406556917033450000000; - int256 constant MAX_HM = 96714065569170334; - - function encodeLocationIdXY(int _x, int _y) internal pure returns (uint result) { - return encodeLocationId3D(_x, _y, 0); - } - - function decodeLocationIdXY(uint _positionId) internal pure returns (int _x, int _y) { - (_x, _y, ) = decodeLocationId3D(_positionId); - } - - function encodeLocationId3D(int _x, int _y, int _z) internal pure returns (uint result) { - return _unsafeEncodeLocationId3D(_x, _y, _z); - } - - function _unsafeEncodeLocationId3D(int _x, int _y, int _z) internal pure returns (uint) { - require(_x >= MIN_Location_XYZ && _x <= MAX_Location_XYZ, "Invalid value."); - require(_y >= MIN_Location_XYZ && _y <= MAX_Location_XYZ, "Invalid value."); - require(_z >= MIN_Location_XYZ && _z <= MAX_Location_XYZ, "Invalid value."); - - // uint256 constant FACTOR_2 = 0x1000000000000000000000000000000000000000000; // <16 ** 42> or <2 ** 168> - // uint256 constant FACTOR = 0x1000000000000000000000; // <16 ** 21> or <2 ** 84> - return ((uint(_x) << 168) & CLEAR_YZ) | (uint(_y << 84) & CLEAR_XZ) | (uint(_z) & CLEAR_XY) | NOT_ZERO; - } - - function decodeLocationId3D(uint _positionId) internal pure returns (int, int, int) { - return _unsafeDecodeLocationId3D(_positionId); - } - - function _unsafeDecodeLocationId3D(uint _value) internal pure returns (int x, int y, int z) { - require(_value >= NOT_ZERO && _value < MAX_LOCATION_ID, "Invalid Location Id"); - - x = expandNegative84BitCast((_value & CLEAR_YZ) >> 168); - y = expandNegative84BitCast((_value & CLEAR_XZ) >> 84); - z = expandNegative84BitCast(_value & CLEAR_XY); - } - - function toHM(int _x) internal pure returns (int) { - return (_x + MAX_HM_DECIMAL)/HMETER_DECIMAL - MAX_HM; - } - - function toUM(int _x) internal pure returns (int) { - return _x * LocationCoder.HMETER_DECIMAL; - } - - function expandNegative84BitCast(uint _value) internal pure returns (int) { - if (_value & (1<<83) != 0) { - return int(_value | APPEND_HIGH); - } - return int(_value); - } - - function encodeLocationIdHM(int _x, int _y) internal pure returns (uint result) { - return encodeLocationIdXY(toUM(_x), toUM(_y)); - } - - function decodeLocationIdHM(uint _positionId) internal pure returns (int, int) { - (int _x, int _y) = decodeLocationIdXY(_positionId); - return (toHM(_x), toHM(_y)); - } -} - -// Dependency file: @evolutionland/common/contracts/TokenLocation.sol - -// pragma solidity ^0.4.24; - -// import "@evolutionland/common/contracts/interfaces/ITokenLocation.sol"; -// import "@evolutionland/common/contracts/DSAuth.sol"; -// import "@evolutionland/common/contracts/LocationCoder.sol"; - -contract TokenLocation is DSAuth, ITokenLocation { - using LocationCoder for *; - - bool private singletonLock = false; - - // token id => encode(x,y) postiion in map, the location is in micron. - mapping (uint256 => uint256) public tokenId2LocationId; - - /* - * Modifiers - */ - modifier singletonLockCall() { - require(!singletonLock, "Only can call once"); - _; - singletonLock = true; - } - - function initializeContract() public singletonLockCall { - owner = msg.sender; - emit LogSetOwner(msg.sender); - } - - function hasLocation(uint256 _tokenId) public view returns (bool) { - return tokenId2LocationId[_tokenId] != 0; - } - - function getTokenLocationHM(uint256 _tokenId) public view returns (int, int){ - (int _x, int _y) = getTokenLocation(_tokenId); - return (LocationCoder.toHM(_x), LocationCoder.toHM(_y)); - } - - function setTokenLocationHM(uint256 _tokenId, int _x, int _y) public auth { - setTokenLocation(_tokenId, LocationCoder.toUM(_x), LocationCoder.toUM(_y)); - } - - // decode tokenId to get (x,y) - function getTokenLocation(uint256 _tokenId) public view returns (int, int) { - uint locationId = tokenId2LocationId[_tokenId]; - return LocationCoder.decodeLocationIdXY(locationId); - } - - function setTokenLocation(uint256 _tokenId, int _x, int _y) public auth { - tokenId2LocationId[_tokenId] = LocationCoder.encodeLocationIdXY(_x, _y); - } -} - -// Dependency file: @evolutionland/common/contracts/ObjectOwnershipAuthority.sol - -// pragma solidity ^0.4.24; - -contract ObjectOwnershipAuthority { - - mapping (address => bool) public whiteList; - - constructor(address[] _whitelists) public { - for (uint i = 0; i < _whitelists.length; i ++) { - whiteList[_whitelists[i]] = true; - } - } - - function canCall( - address _src, address _dst, bytes4 _sig - ) public view returns (bool) { - return ( whiteList[_src] && _sig == bytes4(keccak256("mintObject(address,uint128)")) ) || - ( whiteList[_src] && _sig == bytes4(keccak256("burnObject(address,uint128)")) ); - } -} - -// Dependency file: @evolutionland/common/contracts/TokenLocationAuthority.sol - -// pragma solidity ^0.4.24; - -contract TokenLocationAuthority { - - mapping (address => bool) public whiteList; - - constructor(address[] _whitelists) public { - for (uint i = 0; i < _whitelists.length; i ++) { - whiteList[_whitelists[i]] = true; - } - } - - function canCall( - address _src, address _dst, bytes4 _sig - ) public view returns (bool) { - return ( whiteList[_src] && _sig == bytes4(keccak256("setTokenLocationHM(uint256,int256,int256)"))) ; - } -} - -// Root file: contracts/DeployAndTest.sol - -pragma solidity ^0.4.23; - -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/InterstellarEncoder.sol'; -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/SettingsRegistry.sol'; -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/SettingIds.sol'; -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/StandardERC223.sol'; -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/ObjectOwnership.sol'; -// import "@evolutionland/upgraeability-using-unstructured-storage/contracts/OwnedUpgradeabilityProxy.sol"; -// import "@evolutionland/common/contracts/TokenLocation.sol"; -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/ObjectOwnershipAuthority.sol'; -// import "@evolutionland/common/contracts/TokenLocationAuthority.sol"; - - -contract DeployAndTest { - -} \ No newline at end of file diff --git a/flat/IItemBar.sol b/flat/IItemBar.sol deleted file mode 100644 index a0da86e..0000000 --- a/flat/IItemBar.sol +++ /dev/null @@ -1,31 +0,0 @@ -// Root file: contracts/interfaces/IItemBar.sol - -pragma solidity ^0.4.24; - -interface IItemBar { - //0x33372e46 - function enhanceStrengthRateOf( - address _resourceToken, - uint256 _tokenId - ) external view returns (uint256); - - function maxAmount() external view returns (uint256); - - //0x993ac21a - function enhanceStrengthRateByIndex( - address _resourceToken, - uint256 _landTokenId, - uint256 _index - ) external view returns (uint256); - - //0x09d367f1 - function getBarItem(uint256 _landTokenId, uint256 _index) - external - view - returns (address, uint256, address); - - function getTokenIdByItem(address _item, uint256 _itemId) - external - view - returns (address, uint256); -} diff --git a/flat/ILandBase.sol b/flat/ILandBase.sol deleted file mode 100644 index 04e4655..0000000 --- a/flat/ILandBase.sol +++ /dev/null @@ -1,37 +0,0 @@ -// Root file: contracts/interfaces/ILandBase.sol - -pragma solidity ^0.4.24; - -contract ILandBase { - - /* - * Event - */ - event ModifiedResourceRate(uint indexed tokenId, address resourceToken, uint16 newResourceRate); - event HasboxSetted(uint indexed tokenId, bool hasBox); - - event ChangedReourceRateAttr(uint indexed tokenId, uint256 attr); - - event ChangedFlagMask(uint indexed tokenId, uint256 newFlagMask); - - event CreatedNewLand(uint indexed tokenId, int x, int y, address beneficiary, uint256 resourceRateAttr, uint256 mask); - - function defineResouceTokenRateAttrId(address _resourceToken, uint8 _attrId) public; - - function setHasBox(uint _landTokenID, bool isHasBox) public; - function isReserved(uint256 _tokenId) public view returns (bool); - function isSpecial(uint256 _tokenId) public view returns (bool); - function isHasBox(uint256 _tokenId) public view returns (bool); - - function getResourceRateAttr(uint _landTokenId) public view returns (uint256); - function setResourceRateAttr(uint _landTokenId, uint256 _newResourceRateAttr) public; - - function getResourceRate(uint _landTokenId, address _resouceToken) public view returns (uint16); - function setResourceRate(uint _landTokenID, address _resourceToken, uint16 _newResouceRate) public; - - function getFlagMask(uint _landTokenId) public view returns (uint256); - - function setFlagMask(uint _landTokenId, uint256 _newFlagMask) public; - - function resourceToken2RateAttrId(address _resourceToken) external view returns (uint256); -} diff --git a/flat/IMetaDataTeller.sol b/flat/IMetaDataTeller.sol deleted file mode 100644 index 653218d..0000000 --- a/flat/IMetaDataTeller.sol +++ /dev/null @@ -1,31 +0,0 @@ -// Root file: contracts/interfaces/IMetaDataTeller.sol - -pragma solidity ^0.4.24; - -interface IMetaDataTeller { - function addTokenMeta( - address _token, - uint16 _grade, - uint112 _strengthRate - ) external; - - //0xf666196d - function getMetaData(address _token, uint256 _id) - external - view - returns ( - uint16, - uint16, - uint16 - ); - - //0x7999a5cf - function getPrefer(address _token) external view returns (uint256); - - //0x33281815 - function getRate( - address _token, - uint256 _id, - uint256 _index - ) external view returns (uint256); -} diff --git a/flat/IMinerObject.sol b/flat/IMinerObject.sol deleted file mode 100644 index f558f2d..0000000 --- a/flat/IMinerObject.sol +++ /dev/null @@ -1,43 +0,0 @@ -// Dependency file: openzeppelin-solidity/contracts/introspection/ERC165.sol - -// pragma solidity ^0.4.24; - - -/** - * @title ERC165 - * @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md - */ -interface ERC165 { - - /** - * @notice Query if a contract implements an interface - * @param _interfaceId The interface identifier, as specified in ERC-165 - * @dev Interface identification is specified in ERC-165. This function - * uses less than 30,000 gas. - */ - function supportsInterface(bytes4 _interfaceId) - external - view - returns (bool); -} - - -// Root file: contracts/interfaces/IMinerObject.sol - -pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - -contract IMinerObject is ERC165 { - bytes4 internal constant InterfaceId_IMinerObject = 0x64272b75; - - /* - * 0x64272b752 === - * bytes4(keccak256('strengthOf(uint256,address)')) - */ - - function strengthOf(uint256 _tokenId, address _resourceToken, uint256 _landTokenId) public view returns (uint256); - - function cachedStrengthOf(uint256 _tokenId, address _resourceToken, uint256 _landTokenId) public returns (uint256); - -} diff --git a/flat/IMysteriousTreasure.sol b/flat/IMysteriousTreasure.sol deleted file mode 100644 index 3dbc415..0000000 --- a/flat/IMysteriousTreasure.sol +++ /dev/null @@ -1,9 +0,0 @@ -// Root file: contracts/interfaces/IMysteriousTreasure.sol - -pragma solidity ^0.4.24; - -contract IMysteriousTreasure { - - function unbox(uint256 _tokenId) public returns (uint, uint, uint, uint, uint); - -} \ No newline at end of file diff --git a/flat/LandBase.sol b/flat/LandBase.sol deleted file mode 100644 index 1f596ce..0000000 --- a/flat/LandBase.sol +++ /dev/null @@ -1,713 +0,0 @@ -// Dependency file: contracts/interfaces/ILandBase.sol - -// pragma solidity ^0.4.24; - -contract ILandBase { - - /* - * Event - */ - event ModifiedResourceRate(uint indexed tokenId, address resourceToken, uint16 newResourceRate); - event HasboxSetted(uint indexed tokenId, bool hasBox); - - event ChangedReourceRateAttr(uint indexed tokenId, uint256 attr); - - event ChangedFlagMask(uint indexed tokenId, uint256 newFlagMask); - - event CreatedNewLand(uint indexed tokenId, int x, int y, address beneficiary, uint256 resourceRateAttr, uint256 mask); - - function defineResouceTokenRateAttrId(address _resourceToken, uint8 _attrId) public; - - function setHasBox(uint _landTokenID, bool isHasBox) public; - function isReserved(uint256 _tokenId) public view returns (bool); - function isSpecial(uint256 _tokenId) public view returns (bool); - function isHasBox(uint256 _tokenId) public view returns (bool); - - function getResourceRateAttr(uint _landTokenId) public view returns (uint256); - function setResourceRateAttr(uint _landTokenId, uint256 _newResourceRateAttr) public; - - function getResourceRate(uint _landTokenId, address _resouceToken) public view returns (uint16); - function setResourceRate(uint _landTokenID, address _resourceToken, uint16 _newResouceRate) public; - - function getFlagMask(uint _landTokenId) public view returns (uint256); - - function setFlagMask(uint _landTokenId, uint256 _newFlagMask) public; - - function resourceToken2RateAttrId(address _resourceToken) external view returns (uint256); -} - - -// Dependency file: openzeppelin-solidity/contracts/introspection/ERC165.sol - -// pragma solidity ^0.4.24; - - -/** - * @title ERC165 - * @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md - */ -interface ERC165 { - - /** - * @notice Query if a contract implements an interface - * @param _interfaceId The interface identifier, as specified in ERC-165 - * @dev Interface identification is specified in ERC-165. This function - * uses less than 30,000 gas. - */ - function supportsInterface(bytes4 _interfaceId) - external - view - returns (bool); -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - - -/** - * @title ERC721 Non-Fungible Token Standard basic interface - * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Basic is ERC165 { - - bytes4 internal constant InterfaceId_ERC721 = 0x80ac58cd; - /* - * 0x80ac58cd === - * bytes4(keccak256('balanceOf(address)')) ^ - * bytes4(keccak256('ownerOf(uint256)')) ^ - * bytes4(keccak256('approve(address,uint256)')) ^ - * bytes4(keccak256('getApproved(uint256)')) ^ - * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ - * bytes4(keccak256('isApprovedForAll(address,address)')) ^ - * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ - * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ - * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) - */ - - bytes4 internal constant InterfaceId_ERC721Exists = 0x4f558e79; - /* - * 0x4f558e79 === - * bytes4(keccak256('exists(uint256)')) - */ - - bytes4 internal constant InterfaceId_ERC721Enumerable = 0x780e9d63; - /** - * 0x780e9d63 === - * bytes4(keccak256('totalSupply()')) ^ - * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) ^ - * bytes4(keccak256('tokenByIndex(uint256)')) - */ - - bytes4 internal constant InterfaceId_ERC721Metadata = 0x5b5e139f; - /** - * 0x5b5e139f === - * bytes4(keccak256('name()')) ^ - * bytes4(keccak256('symbol()')) ^ - * bytes4(keccak256('tokenURI(uint256)')) - */ - - event Transfer( - address indexed _from, - address indexed _to, - uint256 indexed _tokenId - ); - event Approval( - address indexed _owner, - address indexed _approved, - uint256 indexed _tokenId - ); - event ApprovalForAll( - address indexed _owner, - address indexed _operator, - bool _approved - ); - - function balanceOf(address _owner) public view returns (uint256 _balance); - function ownerOf(uint256 _tokenId) public view returns (address _owner); - function exists(uint256 _tokenId) public view returns (bool _exists); - - function approve(address _to, uint256 _tokenId) public; - function getApproved(uint256 _tokenId) - public view returns (address _operator); - - function setApprovalForAll(address _operator, bool _approved) public; - function isApprovedForAll(address _owner, address _operator) - public view returns (bool); - - function transferFrom(address _from, address _to, uint256 _tokenId) public; - function safeTransferFrom(address _from, address _to, uint256 _tokenId) - public; - - function safeTransferFrom( - address _from, - address _to, - uint256 _tokenId, - bytes _data - ) - public; -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol"; - - -/** - * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Enumerable is ERC721Basic { - function totalSupply() public view returns (uint256); - function tokenOfOwnerByIndex( - address _owner, - uint256 _index - ) - public - view - returns (uint256 _tokenId); - - function tokenByIndex(uint256 _index) public view returns (uint256); -} - - -/** - * @title ERC-721 Non-Fungible Token Standard, optional metadata extension - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Metadata is ERC721Basic { - function name() external view returns (string _name); - function symbol() external view returns (string _symbol); - function tokenURI(uint256 _tokenId) public view returns (string); -} - - -/** - * @title ERC-721 Non-Fungible Token Standard, full implementation interface - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721 is ERC721Basic, ERC721Enumerable, ERC721Metadata { -} - - -// Dependency file: @evolutionland/common/contracts/interfaces/IObjectOwnership.sol - -// pragma solidity ^0.4.24; - -contract IObjectOwnership { - function mintObject(address _to, uint128 _objectId) public returns (uint256 _tokenId); - - function burnObject(address _to, uint128 _objectId) public returns (uint256 _tokenId); -} - -// Dependency file: @evolutionland/common/contracts/interfaces/ITokenLocation.sol - -// pragma solidity ^0.4.24; - -contract ITokenLocation { - - function hasLocation(uint256 _tokenId) public view returns (bool); - - function getTokenLocation(uint256 _tokenId) public view returns (int, int); - - function setTokenLocation(uint256 _tokenId, int _x, int _y) public; - - function getTokenLocationHM(uint256 _tokenId) public view returns (int, int); - - function setTokenLocationHM(uint256 _tokenId, int _x, int _y) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/ISettingsRegistry.sol - -// pragma solidity ^0.4.24; - -contract ISettingsRegistry { - enum SettingsValueTypes { NONE, UINT, STRING, ADDRESS, BYTES, BOOL, INT } - - function uintOf(bytes32 _propertyName) public view returns (uint256); - - function stringOf(bytes32 _propertyName) public view returns (string); - - function addressOf(bytes32 _propertyName) public view returns (address); - - function bytesOf(bytes32 _propertyName) public view returns (bytes); - - function boolOf(bytes32 _propertyName) public view returns (bool); - - function intOf(bytes32 _propertyName) public view returns (int); - - function setUintProperty(bytes32 _propertyName, uint _value) public; - - function setStringProperty(bytes32 _propertyName, string _value) public; - - function setAddressProperty(bytes32 _propertyName, address _value) public; - - function setBytesProperty(bytes32 _propertyName, bytes _value) public; - - function setBoolProperty(bytes32 _propertyName, bool _value) public; - - function setIntProperty(bytes32 _propertyName, int _value) public; - - function getValueTypeOf(bytes32 _propertyName) public view returns (uint /* SettingsValueTypes */ ); - - event ChangeProperty(bytes32 indexed _propertyName, uint256 _type); -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IAuthority.sol - -// pragma solidity ^0.4.24; - -contract IAuthority { - function canCall( - address src, address dst, bytes4 sig - ) public view returns (bool); -} - -// Dependency file: @evolutionland/common/contracts/DSAuth.sol - -// pragma solidity ^0.4.24; - -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/IAuthority.sol'; - -contract DSAuthEvents { - event LogSetAuthority (address indexed authority); - event LogSetOwner (address indexed owner); -} - -/** - * @title DSAuth - * @dev The DSAuth contract is reference implement of https://github.com/dapphub/ds-auth - * But in the isAuthorized method, the src from address(this) is remove for safty concern. - */ -contract DSAuth is DSAuthEvents { - IAuthority public authority; - address public owner; - - constructor() public { - owner = msg.sender; - emit LogSetOwner(msg.sender); - } - - function setOwner(address owner_) - public - auth - { - owner = owner_; - emit LogSetOwner(owner); - } - - function setAuthority(IAuthority authority_) - public - auth - { - authority = authority_; - emit LogSetAuthority(authority); - } - - modifier auth { - require(isAuthorized(msg.sender, msg.sig)); - _; - } - - modifier onlyOwner() { - require(msg.sender == owner); - _; - } - - function isAuthorized(address src, bytes4 sig) internal view returns (bool) { - if (src == owner) { - return true; - } else if (authority == IAuthority(0)) { - return false; - } else { - return authority.canCall(src, this, sig); - } - } -} - - -// Dependency file: @evolutionland/common/contracts/SettingIds.sol - -// pragma solidity ^0.4.24; - -/** - Id definitions for SettingsRegistry.sol - Can be used in conjunction with the settings registry to get properties -*/ -contract SettingIds { - bytes32 public constant CONTRACT_RING_ERC20_TOKEN = "CONTRACT_RING_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_KTON_ERC20_TOKEN = "CONTRACT_KTON_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_GOLD_ERC20_TOKEN = "CONTRACT_GOLD_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_WOOD_ERC20_TOKEN = "CONTRACT_WOOD_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_WATER_ERC20_TOKEN = "CONTRACT_WATER_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_FIRE_ERC20_TOKEN = "CONTRACT_FIRE_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_SOIL_ERC20_TOKEN = "CONTRACT_SOIL_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_OBJECT_OWNERSHIP = "CONTRACT_OBJECT_OWNERSHIP"; - - bytes32 public constant CONTRACT_TOKEN_LOCATION = "CONTRACT_TOKEN_LOCATION"; - - bytes32 public constant CONTRACT_LAND_BASE = "CONTRACT_LAND_BASE"; - - bytes32 public constant CONTRACT_USER_POINTS = "CONTRACT_USER_POINTS"; - - bytes32 public constant CONTRACT_INTERSTELLAR_ENCODER = "CONTRACT_INTERSTELLAR_ENCODER"; - - bytes32 public constant CONTRACT_DIVIDENDS_POOL = "CONTRACT_DIVIDENDS_POOL"; - - bytes32 public constant CONTRACT_TOKEN_USE = "CONTRACT_TOKEN_USE"; - - bytes32 public constant CONTRACT_REVENUE_POOL = "CONTRACT_REVENUE_POOL"; - - bytes32 public constant CONTRACT_ERC721_BRIDGE = "CONTRACT_ERC721_BRIDGE"; - - bytes32 public constant CONTRACT_PET_BASE = "CONTRACT_PET_BASE"; - - // Cut owner takes on each auction, measured in basis points (1/100 of a percent). - // this can be considered as transaction fee. - // Values 0-10,000 map to 0%-100% - // set ownerCut to 4% - // ownerCut = 400; - bytes32 public constant UINT_AUCTION_CUT = "UINT_AUCTION_CUT"; // Denominator is 10000 - - bytes32 public constant UINT_TOKEN_OFFER_CUT = "UINT_TOKEN_OFFER_CUT"; // Denominator is 10000 - - // Cut referer takes on each auction, measured in basis points (1/100 of a percent). - // which cut from transaction fee. - // Values 0-10,000 map to 0%-100% - // set refererCut to 4% - // refererCut = 400; - bytes32 public constant UINT_REFERER_CUT = "UINT_REFERER_CUT"; - - bytes32 public constant CONTRACT_LAND_RESOURCE = "CONTRACT_LAND_RESOURCE"; -} - -// Dependency file: @evolutionland/common/contracts/LocationCoder.sol - -// pragma solidity ^0.4.24; - -library LocationCoder { - // the allocation of the [x, y, z] is [0<1>, x<21>, y<21>, z<21>] - uint256 constant CLEAR_YZ = 0x0fffffffffffffffffffff000000000000000000000000000000000000000000; - uint256 constant CLEAR_XZ = 0x0000000000000000000000fffffffffffffffffffff000000000000000000000; - uint256 constant CLEAR_XY = 0x0000000000000000000000000000000000000000000fffffffffffffffffffff; - - uint256 constant NOT_ZERO = 0x1000000000000000000000000000000000000000000000000000000000000000; - uint256 constant APPEND_HIGH = 0xfffffffffffffffffffffffffffffffffffffffffff000000000000000000000; - - uint256 constant MAX_LOCATION_ID = 0x2000000000000000000000000000000000000000000000000000000000000000; - - int256 constant HMETER_DECIMAL = 10 ** 8; - - // x, y, z should between -2^83 (-9671406556917033397649408) and 2^83 - 1 (9671406556917033397649407). - int256 constant MIN_Location_XYZ = -9671406556917033397649408; - int256 constant MAX_Location_XYZ = 9671406556917033397649407; - // 96714065569170334.50000000 - int256 constant MAX_HM_DECIMAL = 9671406556917033450000000; - int256 constant MAX_HM = 96714065569170334; - - function encodeLocationIdXY(int _x, int _y) internal pure returns (uint result) { - return encodeLocationId3D(_x, _y, 0); - } - - function decodeLocationIdXY(uint _positionId) internal pure returns (int _x, int _y) { - (_x, _y, ) = decodeLocationId3D(_positionId); - } - - function encodeLocationId3D(int _x, int _y, int _z) internal pure returns (uint result) { - return _unsafeEncodeLocationId3D(_x, _y, _z); - } - - function _unsafeEncodeLocationId3D(int _x, int _y, int _z) internal pure returns (uint) { - require(_x >= MIN_Location_XYZ && _x <= MAX_Location_XYZ, "Invalid value."); - require(_y >= MIN_Location_XYZ && _y <= MAX_Location_XYZ, "Invalid value."); - require(_z >= MIN_Location_XYZ && _z <= MAX_Location_XYZ, "Invalid value."); - - // uint256 constant FACTOR_2 = 0x1000000000000000000000000000000000000000000; // <16 ** 42> or <2 ** 168> - // uint256 constant FACTOR = 0x1000000000000000000000; // <16 ** 21> or <2 ** 84> - return ((uint(_x) << 168) & CLEAR_YZ) | (uint(_y << 84) & CLEAR_XZ) | (uint(_z) & CLEAR_XY) | NOT_ZERO; - } - - function decodeLocationId3D(uint _positionId) internal pure returns (int, int, int) { - return _unsafeDecodeLocationId3D(_positionId); - } - - function _unsafeDecodeLocationId3D(uint _value) internal pure returns (int x, int y, int z) { - require(_value >= NOT_ZERO && _value < MAX_LOCATION_ID, "Invalid Location Id"); - - x = expandNegative84BitCast((_value & CLEAR_YZ) >> 168); - y = expandNegative84BitCast((_value & CLEAR_XZ) >> 84); - z = expandNegative84BitCast(_value & CLEAR_XY); - } - - function toHM(int _x) internal pure returns (int) { - return (_x + MAX_HM_DECIMAL)/HMETER_DECIMAL - MAX_HM; - } - - function toUM(int _x) internal pure returns (int) { - return _x * LocationCoder.HMETER_DECIMAL; - } - - function expandNegative84BitCast(uint _value) internal pure returns (int) { - if (_value & (1<<83) != 0) { - return int(_value | APPEND_HIGH); - } - return int(_value); - } - - function encodeLocationIdHM(int _x, int _y) internal pure returns (uint result) { - return encodeLocationIdXY(toUM(_x), toUM(_y)); - } - - function decodeLocationIdHM(uint _positionId) internal pure returns (int, int) { - (int _x, int _y) = decodeLocationIdXY(_positionId); - return (toHM(_x), toHM(_y)); - } -} - -// Root file: contracts/LandBase.sol - -pragma solidity ^0.4.24; - -// import "contracts/interfaces/ILandBase.sol"; -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; -// import "@evolutionland/common/contracts/interfaces/IObjectOwnership.sol"; -// import "@evolutionland/common/contracts/interfaces/ITokenLocation.sol"; -// import "@evolutionland/common/contracts/interfaces/ISettingsRegistry.sol"; -// import "@evolutionland/common/contracts/DSAuth.sol"; -// import "@evolutionland/common/contracts/SettingIds.sol"; -// import "@evolutionland/common/contracts/LocationCoder.sol"; - -contract LandBase is DSAuth, ILandBase, SettingIds { - using LocationCoder for *; - - uint256 constant internal RESERVED = uint256(1); - uint256 constant internal SPECIAL = uint256(2); - uint256 constant internal HASBOX = uint256(4); - - uint256 constant internal CLEAR_RATE_HIGH = 0x000000000000000000000000000000000000000000000000000000000000ffff; - - struct LandAttr { - uint256 resourceRateAttr; - uint256 mask; - } - - bool private singletonLock = false; - - ISettingsRegistry public registry; - - /** - * @dev mapping from resource token address to resource atrribute rate id. - * atrribute rate id starts from 1 to 16, NAN is 0. - * goldrate is 1, woodrate is 2, waterrate is 3, firerate is 4, soilrate is 5 - */ - mapping (address => uint8) public resourceToken2RateAttrId; - - /** - * @dev mapping from token id to land resource atrribute. - */ - mapping (uint256 => LandAttr) public tokenId2LandAttr; - - // mapping from position in map to token id. - mapping (uint256 => uint256) public locationId2TokenId; - - uint256 public lastLandObjectId; - - /* - * Modifiers - */ - modifier singletonLockCall() { - require(!singletonLock, "Only can call once"); - _; - singletonLock = true; - } - - modifier xAtlantisRangeLimit(int _x) { - require(_x >= -112 && _x <= -68, "Invalid range."); - _; - } - - modifier yAtlantisRangeLimit(int _y) { - require(_y >= -22 && _y <= 22, "Invalid range."); - _; - } - - /** - * @dev Same with constructor, but is used and called by storage proxy as logic contract. - */ - function initializeContract(address _registry) public singletonLockCall { - // Ownable constructor - owner = msg.sender; - emit LogSetOwner(msg.sender); - - registry = ISettingsRegistry(_registry); - - // update attributes. - resourceToken2RateAttrId[registry.addressOf(CONTRACT_GOLD_ERC20_TOKEN)] = 1; - resourceToken2RateAttrId[registry.addressOf(CONTRACT_WOOD_ERC20_TOKEN)] = 2; - resourceToken2RateAttrId[registry.addressOf(CONTRACT_WATER_ERC20_TOKEN)] = 3; - resourceToken2RateAttrId[registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN)] = 4; - resourceToken2RateAttrId[registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN)] = 5; - } - - /* - * @dev assign new land - */ - function assignNewLand( - int _x, int _y, address _beneficiary, uint256 _resourceRateAttr, uint256 _mask - ) public auth xAtlantisRangeLimit(_x) yAtlantisRangeLimit(_y) returns (uint _tokenId) { - - // auto increase object id, start from 1 - lastLandObjectId += 1; - require(lastLandObjectId <= 340282366920938463463374607431768211455, "Can not be stored with 128 bits."); - - _tokenId = IObjectOwnership(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).mintObject(_beneficiary, uint128(lastLandObjectId)); - - // update locations. - uint256 locationId = LocationCoder.encodeLocationIdHM(_x, _y); - require(locationId2TokenId[locationId] == 0, "Land in this position already been mint."); - locationId2TokenId[locationId] = _tokenId; - ITokenLocation(registry.addressOf(CONTRACT_TOKEN_LOCATION)).setTokenLocationHM(_tokenId, _x, _y); - - tokenId2LandAttr[_tokenId].resourceRateAttr = _resourceRateAttr; - tokenId2LandAttr[_tokenId].mask = _mask; - - emit CreatedNewLand(_tokenId, _x, _y, _beneficiary, _resourceRateAttr, _mask); - } - - function assignMultipleLands( - int[] _xs, int[] _ys, address _beneficiary, uint256[] _resourceRateAttrs, uint256[] _masks - ) public auth returns (uint[]){ - require(_xs.length == _ys.length, "Length of xs didn't match length of ys"); - require(_xs.length == _resourceRateAttrs.length, "Length of postions didn't match length of land attributes"); - require(_xs.length == _masks.length, "Length of masks didn't match length of ys"); - - uint[] memory _tokenIds = new uint[](_xs.length); - - for (uint i = 0; i < _xs.length; i++) { - _tokenIds[i] = assignNewLand(_xs[i], _ys[i], _beneficiary, _resourceRateAttrs[i], _masks[i]); - } - - return _tokenIds; - } - - function defineResouceTokenRateAttrId(address _resourceToken, uint8 _attrId) public auth { - require(_attrId > 0 && _attrId <= 16, "Invalid Attr Id."); - - resourceToken2RateAttrId[_resourceToken] = _attrId; - } - - // encode (x,y) to get tokenId - function getTokenIdByLocation(int _x, int _y) public view returns (uint256) { - uint locationId = LocationCoder.encodeLocationIdHM(_x, _y); - return locationId2TokenId[locationId]; - } - - function exists(int _x, int _y) public view returns (bool) { - uint locationId = LocationCoder.encodeLocationIdHM(_x, _y); - uint tokenId = locationId2TokenId[locationId]; - return ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).exists(tokenId); - } - - function ownerOfLand(int _x, int _y) public view returns (address) { - uint locationId = LocationCoder.encodeLocationIdHM(_x, _y); - uint tokenId = locationId2TokenId[locationId]; - return ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(tokenId); - } - - function ownerOfLandMany(int[] _xs, int[] _ys) public view returns (address[]) { - require(_xs.length > 0); - require(_xs.length == _ys.length); - - address[] memory addrs = new address[](_xs.length); - for (uint i = 0; i < _xs.length; i++) { - addrs[i] = ownerOfLand(_xs[i], _ys[i]); - } - - return addrs; - } - - function landOf(address _landholder) public view returns (int[], int[]) { - address objectOwnership = registry.addressOf(CONTRACT_OBJECT_OWNERSHIP); - uint256 length = ERC721(objectOwnership).balanceOf(_landholder); - int[] memory x = new int[](length); - int[] memory y = new int[](length); - - ITokenLocation tokenLocation = ITokenLocation(registry.addressOf(CONTRACT_TOKEN_LOCATION)); - - for(uint i = 0; i < length; i++) { - uint tokenId = ERC721(objectOwnership).tokenOfOwnerByIndex(_landholder, i); - (x[i], y[i]) = tokenLocation.getTokenLocationHM(tokenId); - } - - return (x, y); - } - - function isHasBox(uint256 _landTokenID) public view returns (bool) { - return (tokenId2LandAttr[_landTokenID].mask & HASBOX) != 0; - } - - function isReserved(uint256 _landTokenID) public view returns (bool) { - return (tokenId2LandAttr[_landTokenID].mask & RESERVED) != 0; - } - - function isSpecial(uint256 _landTokenID) public view returns (bool) { - return (tokenId2LandAttr[_landTokenID].mask & SPECIAL) != 0; - } - - function setHasBox(uint _landTokenID, bool _isHasBox) public auth { - if (_isHasBox) { - tokenId2LandAttr[_landTokenID].mask |= HASBOX; - } else { - tokenId2LandAttr[_landTokenID].mask &= ~HASBOX; - } - - emit HasboxSetted(_landTokenID, _isHasBox); - } - - function getResourceRateAttr(uint _landTokenId) public view returns (uint256) { - return tokenId2LandAttr[_landTokenId].resourceRateAttr; - } - - function setResourceRateAttr(uint _landTokenId, uint256 _newResourceRateAttr) public auth { - tokenId2LandAttr[_landTokenId].resourceRateAttr = _newResourceRateAttr; - - emit ChangedReourceRateAttr(_landTokenId, _newResourceRateAttr); - } - - function getFlagMask(uint _landTokenId) public view returns (uint256) { - return tokenId2LandAttr[_landTokenId].mask; - } - - function setFlagMask(uint _landTokenId, uint256 _newFlagMask) public auth { - tokenId2LandAttr[_landTokenId].mask = _newFlagMask; - emit ChangedFlagMask(_landTokenId, _newFlagMask); - } - - function getResourceRate(uint _landTokenId, address _resourceToken) public view returns (uint16) { - require(resourceToken2RateAttrId[_resourceToken] > 0, "Resource token doesn't exist."); - - uint moveRight = (16 * (resourceToken2RateAttrId[_resourceToken] - 1)); - return uint16((tokenId2LandAttr[_landTokenId].resourceRateAttr >> moveRight) & CLEAR_RATE_HIGH); - } - - function setResourceRate(uint _landTokenId, address _resourceToken, uint16 _newResouceRate) public auth { - require(resourceToken2RateAttrId[_resourceToken] > 0, "Reource token doesn't exist."); - uint moveLeft = 16 * (resourceToken2RateAttrId[_resourceToken] - 1); - tokenId2LandAttr[_landTokenId].resourceRateAttr &= (~(CLEAR_RATE_HIGH << moveLeft)); - tokenId2LandAttr[_landTokenId].resourceRateAttr |= (uint256(_newResouceRate) << moveLeft); - emit ModifiedResourceRate(_landTokenId, _resourceToken, _newResouceRate); - } -} diff --git a/flat/LandBaseAuthority.sol b/flat/LandBaseAuthority.sol deleted file mode 100644 index 1bfd010..0000000 --- a/flat/LandBaseAuthority.sol +++ /dev/null @@ -1,23 +0,0 @@ -// Root file: contracts/LandBaseAuthority.sol - -pragma solidity ^0.4.24; - -contract LandBaseAuthority { - - constructor(address[] _whitelists) public { - for (uint i = 0; i < _whitelists.length; i ++) { - whiteList[_whitelists[i]] = true; - } - } - - mapping (address => bool) public whiteList; - - function canCall( - address _src, address _dst, bytes4 _sig - ) public view returns (bool) { - return ( whiteList[_src] && _sig == bytes4(keccak256("setResourceRateAttr(uint256,uint256)")) ) || - ( whiteList[_src] && _sig == bytes4(keccak256("setResourceRate(uint256,address,uint16)")) ) || - ( whiteList[_src] && _sig == bytes4(keccak256("setHasBox(uint256,bool)"))) || - ( whiteList[_src] && _sig == bytes4(keccak256("assignNewLand(int256,int256,address,uint256,uint256)"))); - } -} \ No newline at end of file diff --git a/flat/LandResource.sol b/flat/LandResource.sol deleted file mode 100644 index c4f0d09..0000000 --- a/flat/LandResource.sol +++ /dev/null @@ -1,1001 +0,0 @@ -// Dependency file: openzeppelin-solidity/contracts/math/SafeMath.sol - -// pragma solidity ^0.4.24; - - -/** - * @title SafeMath - * @dev Math operations with safety checks that throw on error - */ -library SafeMath { - - /** - * @dev Multiplies two numbers, throws on overflow. - */ - function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) { - // Gas optimization: this is cheaper than asserting 'a' not being zero, but the - // benefit is lost if 'b' is also tested. - // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 - if (_a == 0) { - return 0; - } - - c = _a * _b; - assert(c / _a == _b); - return c; - } - - /** - * @dev Integer division of two numbers, truncating the quotient. - */ - function div(uint256 _a, uint256 _b) internal pure returns (uint256) { - // assert(_b > 0); // Solidity automatically throws when dividing by 0 - // uint256 c = _a / _b; - // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold - return _a / _b; - } - - /** - * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). - */ - function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { - assert(_b <= _a); - return _a - _b; - } - - /** - * @dev Adds two numbers, throws on overflow. - */ - function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) { - c = _a + _b; - assert(c >= _a); - return c; - } -} - - -// Dependency file: openzeppelin-solidity/contracts/introspection/ERC165.sol - -// pragma solidity ^0.4.24; - - -/** - * @title ERC165 - * @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md - */ -interface ERC165 { - - /** - * @notice Query if a contract implements an interface - * @param _interfaceId The interface identifier, as specified in ERC-165 - * @dev Interface identification is specified in ERC-165. This function - * uses less than 30,000 gas. - */ - function supportsInterface(bytes4 _interfaceId) - external - view - returns (bool); -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - - -/** - * @title ERC721 Non-Fungible Token Standard basic interface - * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Basic is ERC165 { - - bytes4 internal constant InterfaceId_ERC721 = 0x80ac58cd; - /* - * 0x80ac58cd === - * bytes4(keccak256('balanceOf(address)')) ^ - * bytes4(keccak256('ownerOf(uint256)')) ^ - * bytes4(keccak256('approve(address,uint256)')) ^ - * bytes4(keccak256('getApproved(uint256)')) ^ - * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ - * bytes4(keccak256('isApprovedForAll(address,address)')) ^ - * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ - * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ - * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) - */ - - bytes4 internal constant InterfaceId_ERC721Exists = 0x4f558e79; - /* - * 0x4f558e79 === - * bytes4(keccak256('exists(uint256)')) - */ - - bytes4 internal constant InterfaceId_ERC721Enumerable = 0x780e9d63; - /** - * 0x780e9d63 === - * bytes4(keccak256('totalSupply()')) ^ - * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) ^ - * bytes4(keccak256('tokenByIndex(uint256)')) - */ - - bytes4 internal constant InterfaceId_ERC721Metadata = 0x5b5e139f; - /** - * 0x5b5e139f === - * bytes4(keccak256('name()')) ^ - * bytes4(keccak256('symbol()')) ^ - * bytes4(keccak256('tokenURI(uint256)')) - */ - - event Transfer( - address indexed _from, - address indexed _to, - uint256 indexed _tokenId - ); - event Approval( - address indexed _owner, - address indexed _approved, - uint256 indexed _tokenId - ); - event ApprovalForAll( - address indexed _owner, - address indexed _operator, - bool _approved - ); - - function balanceOf(address _owner) public view returns (uint256 _balance); - function ownerOf(uint256 _tokenId) public view returns (address _owner); - function exists(uint256 _tokenId) public view returns (bool _exists); - - function approve(address _to, uint256 _tokenId) public; - function getApproved(uint256 _tokenId) - public view returns (address _operator); - - function setApprovalForAll(address _operator, bool _approved) public; - function isApprovedForAll(address _owner, address _operator) - public view returns (bool); - - function transferFrom(address _from, address _to, uint256 _tokenId) public; - function safeTransferFrom(address _from, address _to, uint256 _tokenId) - public; - - function safeTransferFrom( - address _from, - address _to, - uint256 _tokenId, - bytes _data - ) - public; -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol"; - - -/** - * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Enumerable is ERC721Basic { - function totalSupply() public view returns (uint256); - function tokenOfOwnerByIndex( - address _owner, - uint256 _index - ) - public - view - returns (uint256 _tokenId); - - function tokenByIndex(uint256 _index) public view returns (uint256); -} - - -/** - * @title ERC-721 Non-Fungible Token Standard, optional metadata extension - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Metadata is ERC721Basic { - function name() external view returns (string _name); - function symbol() external view returns (string _symbol); - function tokenURI(uint256 _tokenId) public view returns (string); -} - - -/** - * @title ERC-721 Non-Fungible Token Standard, full implementation interface - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721 is ERC721Basic, ERC721Enumerable, ERC721Metadata { -} - - -// Dependency file: openzeppelin-solidity/contracts/introspection/SupportsInterfaceWithLookup.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - - -/** - * @title SupportsInterfaceWithLookup - * @author Matt Condon (@shrugs) - * @dev Implements ERC165 using a lookup table. - */ -contract SupportsInterfaceWithLookup is ERC165 { - - bytes4 public constant InterfaceId_ERC165 = 0x01ffc9a7; - /** - * 0x01ffc9a7 === - * bytes4(keccak256('supportsInterface(bytes4)')) - */ - - /** - * @dev a mapping of interface id to whether or not it's supported - */ - mapping(bytes4 => bool) internal supportedInterfaces; - - /** - * @dev A contract implementing SupportsInterfaceWithLookup - * implement ERC165 itself - */ - constructor() - public - { - _registerInterface(InterfaceId_ERC165); - } - - /** - * @dev implement supportsInterface(bytes4) using a lookup table - */ - function supportsInterface(bytes4 _interfaceId) - external - view - returns (bool) - { - return supportedInterfaces[_interfaceId]; - } - - /** - * @dev private method for registering an interface - */ - function _registerInterface(bytes4 _interfaceId) - internal - { - require(_interfaceId != 0xffffffff); - supportedInterfaces[_interfaceId] = true; - } -} - - -// Dependency file: @evolutionland/common/contracts/interfaces/IMintableERC20.sol - -// pragma solidity ^0.4.23; - -contract IMintableERC20 { - - function mint(address _to, uint256 _value) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/ISettingsRegistry.sol - -// pragma solidity ^0.4.24; - -contract ISettingsRegistry { - enum SettingsValueTypes { NONE, UINT, STRING, ADDRESS, BYTES, BOOL, INT } - - function uintOf(bytes32 _propertyName) public view returns (uint256); - - function stringOf(bytes32 _propertyName) public view returns (string); - - function addressOf(bytes32 _propertyName) public view returns (address); - - function bytesOf(bytes32 _propertyName) public view returns (bytes); - - function boolOf(bytes32 _propertyName) public view returns (bool); - - function intOf(bytes32 _propertyName) public view returns (int); - - function setUintProperty(bytes32 _propertyName, uint _value) public; - - function setStringProperty(bytes32 _propertyName, string _value) public; - - function setAddressProperty(bytes32 _propertyName, address _value) public; - - function setBytesProperty(bytes32 _propertyName, bytes _value) public; - - function setBoolProperty(bytes32 _propertyName, bool _value) public; - - function setIntProperty(bytes32 _propertyName, int _value) public; - - function getValueTypeOf(bytes32 _propertyName) public view returns (uint /* SettingsValueTypes */ ); - - event ChangeProperty(bytes32 indexed _propertyName, uint256 _type); -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IAuthority.sol - -// pragma solidity ^0.4.24; - -contract IAuthority { - function canCall( - address src, address dst, bytes4 sig - ) public view returns (bool); -} - -// Dependency file: @evolutionland/common/contracts/DSAuth.sol - -// pragma solidity ^0.4.24; - -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/IAuthority.sol'; - -contract DSAuthEvents { - event LogSetAuthority (address indexed authority); - event LogSetOwner (address indexed owner); -} - -/** - * @title DSAuth - * @dev The DSAuth contract is reference implement of https://github.com/dapphub/ds-auth - * But in the isAuthorized method, the src from address(this) is remove for safty concern. - */ -contract DSAuth is DSAuthEvents { - IAuthority public authority; - address public owner; - - constructor() public { - owner = msg.sender; - emit LogSetOwner(msg.sender); - } - - function setOwner(address owner_) - public - auth - { - owner = owner_; - emit LogSetOwner(owner); - } - - function setAuthority(IAuthority authority_) - public - auth - { - authority = authority_; - emit LogSetAuthority(authority); - } - - modifier auth { - require(isAuthorized(msg.sender, msg.sig)); - _; - } - - modifier onlyOwner() { - require(msg.sender == owner); - _; - } - - function isAuthorized(address src, bytes4 sig) internal view returns (bool) { - if (src == owner) { - return true; - } else if (authority == IAuthority(0)) { - return false; - } else { - return authority.canCall(src, this, sig); - } - } -} - - -// Dependency file: @evolutionland/common/contracts/SettingIds.sol - -// pragma solidity ^0.4.24; - -/** - Id definitions for SettingsRegistry.sol - Can be used in conjunction with the settings registry to get properties -*/ -contract SettingIds { - bytes32 public constant CONTRACT_RING_ERC20_TOKEN = "CONTRACT_RING_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_KTON_ERC20_TOKEN = "CONTRACT_KTON_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_GOLD_ERC20_TOKEN = "CONTRACT_GOLD_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_WOOD_ERC20_TOKEN = "CONTRACT_WOOD_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_WATER_ERC20_TOKEN = "CONTRACT_WATER_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_FIRE_ERC20_TOKEN = "CONTRACT_FIRE_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_SOIL_ERC20_TOKEN = "CONTRACT_SOIL_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_OBJECT_OWNERSHIP = "CONTRACT_OBJECT_OWNERSHIP"; - - bytes32 public constant CONTRACT_TOKEN_LOCATION = "CONTRACT_TOKEN_LOCATION"; - - bytes32 public constant CONTRACT_LAND_BASE = "CONTRACT_LAND_BASE"; - - bytes32 public constant CONTRACT_USER_POINTS = "CONTRACT_USER_POINTS"; - - bytes32 public constant CONTRACT_INTERSTELLAR_ENCODER = "CONTRACT_INTERSTELLAR_ENCODER"; - - bytes32 public constant CONTRACT_DIVIDENDS_POOL = "CONTRACT_DIVIDENDS_POOL"; - - bytes32 public constant CONTRACT_TOKEN_USE = "CONTRACT_TOKEN_USE"; - - bytes32 public constant CONTRACT_REVENUE_POOL = "CONTRACT_REVENUE_POOL"; - - bytes32 public constant CONTRACT_ERC721_BRIDGE = "CONTRACT_ERC721_BRIDGE"; - - bytes32 public constant CONTRACT_PET_BASE = "CONTRACT_PET_BASE"; - - // Cut owner takes on each auction, measured in basis points (1/100 of a percent). - // this can be considered as transaction fee. - // Values 0-10,000 map to 0%-100% - // set ownerCut to 4% - // ownerCut = 400; - bytes32 public constant UINT_AUCTION_CUT = "UINT_AUCTION_CUT"; // Denominator is 10000 - - bytes32 public constant UINT_TOKEN_OFFER_CUT = "UINT_TOKEN_OFFER_CUT"; // Denominator is 10000 - - // Cut referer takes on each auction, measured in basis points (1/100 of a percent). - // which cut from transaction fee. - // Values 0-10,000 map to 0%-100% - // set refererCut to 4% - // refererCut = 400; - bytes32 public constant UINT_REFERER_CUT = "UINT_REFERER_CUT"; - - bytes32 public constant CONTRACT_LAND_RESOURCE = "CONTRACT_LAND_RESOURCE"; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IInterstellarEncoder.sol - -// pragma solidity ^0.4.24; - -contract IInterstellarEncoder { - uint256 constant CLEAR_HIGH = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff; - - uint256 public constant MAGIC_NUMBER = 42; // Interstellar Encoding Magic Number. - uint256 public constant CHAIN_ID = 1; // Ethereum mainet. - uint256 public constant CURRENT_LAND = 1; // 1 is Atlantis, 0 is NaN. - - enum ObjectClass { - NaN, - LAND, - APOSTLE, - OBJECT_CLASS_COUNT - } - - function registerNewObjectClass(address _objectContract, uint8 objectClass) public; - - function registerNewTokenContract(address _tokenAddress) public; - - function encodeTokenId(address _tokenAddress, uint8 _objectClass, uint128 _objectIndex) public view returns (uint256 _tokenId); - - function encodeTokenIdForObjectContract( - address _tokenAddress, address _objectContract, uint128 _objectId) public view returns (uint256 _tokenId); - - function getContractAddress(uint256 _tokenId) public view returns (address); - - function getObjectId(uint256 _tokenId) public view returns (uint128 _objectId); - - function getObjectClass(uint256 _tokenId) public view returns (uint8); - - function getObjectAddress(uint256 _tokenId) public view returns (address); -} - -// Dependency file: @evolutionland/common/contracts/interfaces/ITokenUse.sol - -// pragma solidity ^0.4.24; - -contract ITokenUse { - uint48 public constant MAX_UINT48_TIME = 281474976710655; - - function isObjectInHireStage(uint256 _tokenId) public view returns (bool); - - function isObjectReadyToUse(uint256 _tokenId) public view returns (bool); - - function getTokenUser(uint256 _tokenId) public view returns (address); - - function createTokenUseOffer(uint256 _tokenId, uint256 _duration, uint256 _price, address _acceptedActivity) public; - - function cancelTokenUseOffer(uint256 _tokenId) public; - - function takeTokenUseOffer(uint256 _tokenId) public; - - function addActivity(uint256 _tokenId, address _user, uint256 _endTime) public; - - function removeActivity(uint256 _tokenId, address _user) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IActivity.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - -contract IActivity is ERC165 { - bytes4 internal constant InterfaceId_IActivity = 0x6086e7f8; - /* - * 0x6086e7f8 === - * bytes4(keccak256('activityStopped(uint256)')) - */ - - function activityStopped(uint256 _tokenId) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IMinerObject.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - -contract IMinerObject is ERC165 { - bytes4 internal constant InterfaceId_IMinerObject = 0x64272b75; - - /* - * 0x64272b752 === - * bytes4(keccak256('strengthOf(uint256,address)')) - */ - - function strengthOf(uint256 _tokenId, address _resourceToken, uint256 _landTokenId) public view returns (uint256); - -} - -// Dependency file: contracts/interfaces/ILandBase.sol - -// pragma solidity ^0.4.24; - -contract ILandBase { - - /* - * Event - */ - event ModifiedResourceRate(uint indexed tokenId, address resourceToken, uint16 newResourceRate); - event HasboxSetted(uint indexed tokenId, bool hasBox); - - event ChangedReourceRateAttr(uint indexed tokenId, uint256 attr); - - event ChangedFlagMask(uint indexed tokenId, uint256 newFlagMask); - - event CreatedNewLand(uint indexed tokenId, int x, int y, address beneficiary, uint256 resourceRateAttr, uint256 mask); - - function defineResouceTokenRateAttrId(address _resourceToken, uint8 _attrId) public; - - function setHasBox(uint _landTokenID, bool isHasBox) public; - function isReserved(uint256 _tokenId) public view returns (bool); - function isSpecial(uint256 _tokenId) public view returns (bool); - function isHasBox(uint256 _tokenId) public view returns (bool); - - function getResourceRateAttr(uint _landTokenId) public view returns (uint256); - function setResourceRateAttr(uint _landTokenId, uint256 _newResourceRateAttr) public; - - function getResourceRate(uint _landTokenId, address _resouceToken) public view returns (uint16); - function setResourceRate(uint _landTokenID, address _resourceToken, uint16 _newResouceRate) public; - - function getFlagMask(uint _landTokenId) public view returns (uint256); - - function setFlagMask(uint _landTokenId, uint256 _newFlagMask) public; - - function resourceToken2RateAttrId(address _resourceToken) external view returns (uint256); -} - - -// Dependency file: contracts/LandSettingIds.sol - -// pragma solidity ^0.4.24; - -// import "@evolutionland/common/contracts/SettingIds.sol"; - -contract LandSettingIds is SettingIds { - -} - -// Root file: contracts/LandResource.sol - -pragma solidity ^0.4.23; - -// import "openzeppelin-solidity/contracts/math/SafeMath.sol"; -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; -// import "openzeppelin-solidity/contracts/introspection/SupportsInterfaceWithLookup.sol"; -// import "@evolutionland/common/contracts/interfaces/IMintableERC20.sol"; -// import "@evolutionland/common/contracts/interfaces/ISettingsRegistry.sol"; -// import "@evolutionland/common/contracts/DSAuth.sol"; -// import "@evolutionland/common/contracts/SettingIds.sol"; -// import "@evolutionland/common/contracts/interfaces/IInterstellarEncoder.sol"; -// import "@evolutionland/common/contracts/interfaces/ITokenUse.sol"; -// import "@evolutionland/common/contracts/interfaces/IActivity.sol"; -// import "@evolutionland/common/contracts/interfaces/IMinerObject.sol"; -// import "contracts/interfaces/ILandBase.sol"; -// import "contracts/LandSettingIds.sol"; - -/** - * @title LandResource - * @dev LandResource is registry that manage the element resources generated on Land, and related resource releasing speed. - */ -contract LandResource is SupportsInterfaceWithLookup, DSAuth, IActivity, LandSettingIds { - using SafeMath for *; - - // For every seconds, the speed will decrease by current speed multiplying (DENOMINATOR_in_seconds - seconds) / DENOMINATOR_in_seconds - // resource will decrease 1/10000 every day. - uint256 public constant DENOMINATOR = 10000; - - uint256 public constant TOTAL_SECONDS = DENOMINATOR * (1 days); - - bool private singletonLock = false; - - ISettingsRegistry public registry; - - uint256 public resourceReleaseStartTime; - - // TODO: move to global settings contract. - uint256 public attenPerDay = 1; - uint256 public recoverAttenPerDay = 20; - - // Struct for recording resouces on land which have already been pinged. - // 金, Evolution Land Gold - // 木, Evolution Land Wood - // 水, Evolution Land Water - // 火, Evolution Land fire - // 土, Evolution Land Silicon - struct ResourceMineState { - mapping(address => uint256) mintedBalance; - mapping(address => uint256[]) miners; - mapping(address => uint256) totalMinerStrength; - uint256 lastUpdateSpeedInSeconds; - uint256 lastDestoryAttenInSeconds; - uint256 industryIndex; - uint128 lastUpdateTime; - uint64 totalMiners; - uint64 maxMiners; - } - - struct MinerStatus { - uint256 landTokenId; - address resource; - uint64 indexInResource; - } - - mapping(uint256 => ResourceMineState) public land2ResourceMineState; - - mapping(uint256 => MinerStatus) public miner2Index; - - /* - * Event - */ - - event StartMining(uint256 minerTokenId, uint256 landTokenId, address _resource, uint256 strength); - event StopMining(uint256 minerTokenId, uint256 landTokenId, address _resource, uint256 strength); - event ResourceClaimed(address owner, uint256 landTokenId, uint256 goldBalance, uint256 woodBalance, uint256 waterBalance, uint256 fireBalance, uint256 soilBalance); - - /* - * Modifiers - */ - modifier singletonLockCall() { - require(!singletonLock, "Only can call once"); - _; - singletonLock = true; - } - - function initializeContract(address _registry, uint256 _resourceReleaseStartTime) public singletonLockCall { - // Ownable constructor - owner = msg.sender; - emit LogSetOwner(msg.sender); - - registry = ISettingsRegistry(_registry); - - resourceReleaseStartTime = _resourceReleaseStartTime; - - _registerInterface(InterfaceId_IActivity); - } - - // get amount of speed uint at this moment - function _getReleaseSpeedInSeconds(uint256 _tokenId, uint256 _time) internal view returns (uint256 currentSpeed) { - require(_time >= resourceReleaseStartTime, "Should after release time"); - require(_time >= land2ResourceMineState[_tokenId].lastUpdateTime, "Should after release last update time"); - - // after 10000 days from start - // the resource release speed decreases to 0 - if (TOTAL_SECONDS < _time - resourceReleaseStartTime) - { - return 0; - } - - // max amount of speed unit of _tokenId for now - // suppose that speed_uint = 1 in this function - uint256 availableSpeedInSeconds = TOTAL_SECONDS.sub(_time - resourceReleaseStartTime); - // time from last update - uint256 timeBetween = _time - land2ResourceMineState[_tokenId].lastUpdateTime; - - // the recover speed is 20/10000, 20 times. - // recoveryRate overall from lasUpdateTime til now + amount of speed uint at lastUpdateTime - uint256 nextSpeedInSeconds = land2ResourceMineState[_tokenId].lastUpdateSpeedInSeconds + timeBetween * recoverAttenPerDay; - // destroyRate overall from lasUpdateTime til now amount of speed uint at lastUpdateTime - uint256 destroyedSpeedInSeconds = timeBetween * land2ResourceMineState[_tokenId].lastDestoryAttenInSeconds; - - if (nextSpeedInSeconds < destroyedSpeedInSeconds) - { - nextSpeedInSeconds = 0; - } else { - nextSpeedInSeconds = nextSpeedInSeconds - destroyedSpeedInSeconds; - } - - if (nextSpeedInSeconds > availableSpeedInSeconds) { - nextSpeedInSeconds = availableSpeedInSeconds; - } - - return nextSpeedInSeconds; - } - - function getReleaseSpeed(uint256 _tokenId, address _resourceToken, uint256 _time) public view returns (uint256 currentSpeed) { - return ILandBase(registry.addressOf(CONTRACT_LAND_BASE)) - .getResourceRate(_tokenId, _resourceToken).mul(_getReleaseSpeedInSeconds(_tokenId, _time)) - .div(TOTAL_SECONDS); - } - - /** - * @dev Get and Query the amount of resources available from lastUpdateTime to now for use on specific land. - * @param _tokenId The token id of specific land. - */ - function _getMinableBalance(uint256 _tokenId, address _resourceToken, uint256 _currentTime, uint256 _lastUpdateTime) public view returns (uint256 minableBalance) { - - uint256 speed_in_current_period = getReleaseSpeed( - _tokenId, _resourceToken, (_currentTime + _lastUpdateTime) / 2); - - // calculate the area of trapezoid - minableBalance = speed_in_current_period.mul(_currentTime - _lastUpdateTime).mul(1 ether).div(1 days); - } - - function _getMaxMineBalance(uint256 _tokenId, address _resourceToken, uint256 _currentTime, uint256 _lastUpdateTime) internal view returns (uint256) { - // totalMinerStrength is in wei - uint256 mineSpeed = land2ResourceMineState[_tokenId].totalMinerStrength[_resourceToken]; - - return mineSpeed.mul(_currentTime - _lastUpdateTime).div(1 days); - } - - function mine(uint256 _landTokenId) public { - _mineAllResource( - _landTokenId, - registry.addressOf(CONTRACT_GOLD_ERC20_TOKEN), - registry.addressOf(CONTRACT_WOOD_ERC20_TOKEN), - registry.addressOf(CONTRACT_WATER_ERC20_TOKEN), - registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN), - registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN) - ); - } - - function _mineAllResource(uint256 _landTokenId, address _gold, address _wood, address _water, address _fire, address _soil) internal { - require(IInterstellarEncoder(registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER)).getObjectClass(_landTokenId) == 1, "Token must be land."); - - if (land2ResourceMineState[_landTokenId].lastUpdateTime == 0) { - land2ResourceMineState[_landTokenId].lastUpdateTime = uint128(resourceReleaseStartTime); - land2ResourceMineState[_landTokenId].lastUpdateSpeedInSeconds = TOTAL_SECONDS; - } - - _mineResource(_landTokenId, _gold); - _mineResource(_landTokenId, _wood); - _mineResource(_landTokenId, _water); - _mineResource(_landTokenId, _fire); - _mineResource(_landTokenId, _soil); - - land2ResourceMineState[_landTokenId].lastUpdateSpeedInSeconds = _getReleaseSpeedInSeconds(_landTokenId, now); - land2ResourceMineState[_landTokenId].lastUpdateTime = uint128(now); - - } - - function _mineResource(uint256 _landTokenId, address _resourceToken) internal { - // the longest seconds to zero speed. - uint minedBalance = _calculateMinedBalance(_landTokenId, _resourceToken, now); - - land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken] += minedBalance; - } - - function _calculateMinedBalance(uint256 _landTokenId, address _resourceToken, uint256 _currentTime) internal returns (uint256) { - uint256 currentTime = _currentTime; - - uint256 minedBalance; - uint256 minableBalance; - if (currentTime > (resourceReleaseStartTime + TOTAL_SECONDS)) - { - currentTime = (resourceReleaseStartTime + TOTAL_SECONDS); - } - - uint256 lastUpdateTime = land2ResourceMineState[_landTokenId].lastUpdateTime; - require(currentTime >= lastUpdateTime); - - if (lastUpdateTime >= (resourceReleaseStartTime + TOTAL_SECONDS)) { - minedBalance = 0; - minableBalance = 0; - } else { - minedBalance = _getMaxMineBalance(_landTokenId, _resourceToken, currentTime, lastUpdateTime); - minableBalance = _getMinableBalance(_landTokenId, _resourceToken, currentTime, lastUpdateTime); - } - - - if (minedBalance > minableBalance) { - minedBalance = minableBalance; - } - - return minedBalance; - } - - function claimAllResource(uint256 _landTokenId) public { - require(msg.sender == ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(_landTokenId), "Must be the owner of the land"); - - address gold = registry.addressOf(CONTRACT_GOLD_ERC20_TOKEN); - address wood = registry.addressOf(CONTRACT_WOOD_ERC20_TOKEN); - address water = registry.addressOf(CONTRACT_WATER_ERC20_TOKEN); - address fire = registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN); - address soil = registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN); - - _mineAllResource(_landTokenId, gold, wood, water, fire, soil); - - uint goldBalance; - uint woodBalance; - uint waterBalance; - uint fireBalance; - uint soilBalance; - - if (land2ResourceMineState[_landTokenId].mintedBalance[gold] > 0) { - goldBalance = land2ResourceMineState[_landTokenId].mintedBalance[gold]; - IMintableERC20(gold).mint(msg.sender, goldBalance); - land2ResourceMineState[_landTokenId].mintedBalance[gold] = 0; - } - - if (land2ResourceMineState[_landTokenId].mintedBalance[wood] > 0) { - woodBalance = land2ResourceMineState[_landTokenId].mintedBalance[wood]; - IMintableERC20(wood).mint(msg.sender, woodBalance); - land2ResourceMineState[_landTokenId].mintedBalance[wood] = 0; - } - - if (land2ResourceMineState[_landTokenId].mintedBalance[water] > 0) { - waterBalance = land2ResourceMineState[_landTokenId].mintedBalance[water]; - IMintableERC20(water).mint(msg.sender, waterBalance); - land2ResourceMineState[_landTokenId].mintedBalance[water] = 0; - } - - if (land2ResourceMineState[_landTokenId].mintedBalance[fire] > 0) { - fireBalance = land2ResourceMineState[_landTokenId].mintedBalance[fire]; - IMintableERC20(fire).mint(msg.sender, fireBalance); - land2ResourceMineState[_landTokenId].mintedBalance[fire] = 0; - } - - if (land2ResourceMineState[_landTokenId].mintedBalance[soil] > 0) { - soilBalance = land2ResourceMineState[_landTokenId].mintedBalance[soil]; - IMintableERC20(soil).mint(msg.sender, soilBalance); - land2ResourceMineState[_landTokenId].mintedBalance[soil] = 0; - } - - emit ResourceClaimed(msg.sender, _landTokenId, goldBalance, woodBalance, waterBalance, fireBalance, soilBalance); - } - - // both for own _tokenId or hired one - function startMining(uint256 _tokenId, uint256 _landTokenId, address _resource) public { - ITokenUse tokenUse = ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)); - - tokenUse.addActivity(_tokenId, msg.sender, 0); - - // require the permission from land owner; - require(msg.sender == ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(_landTokenId), "Must be the owner of the land"); - - // make sure that _tokenId won't be used repeatedly - require(miner2Index[_tokenId].landTokenId == 0); - - // update status! - mine(_landTokenId); - - uint256 _index = land2ResourceMineState[_landTokenId].miners[_resource].length; - - land2ResourceMineState[_landTokenId].totalMiners += 1; - - if (land2ResourceMineState[_landTokenId].maxMiners == 0) { - land2ResourceMineState[_landTokenId].maxMiners = 5; - } - - require(land2ResourceMineState[_landTokenId].totalMiners <= land2ResourceMineState[_landTokenId].maxMiners); - - address miner = IInterstellarEncoder(registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER)).getObjectAddress(_tokenId); - uint256 strength = IMinerObject(miner).strengthOf(_tokenId, _resource, _landTokenId); - - land2ResourceMineState[_landTokenId].miners[_resource].push(_tokenId); - land2ResourceMineState[_landTokenId].totalMinerStrength[_resource] += strength; - - miner2Index[_tokenId] = MinerStatus({ - landTokenId : _landTokenId, - resource : _resource, - indexInResource : uint64(_index) - }); - - emit StartMining(_tokenId, _landTokenId, _resource, strength); - - } - - function batchStartMining(uint256[] _tokenIds, uint256[] _landTokenIds, address[] _resources) public { - require(_tokenIds.length == _landTokenIds.length && _landTokenIds.length == _resources.length, "input error"); - uint length = _tokenIds.length; - - for (uint i = 0; i < length; i++) { - startMining(_tokenIds[i], _landTokenIds[i], _resources[i]); - } - - } - - // Only trigger from Token Activity. - function activityStopped(uint256 _tokenId) public auth { - - _stopMining(_tokenId); - } - - function stopMining(uint256 _tokenId) public { - ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).removeActivity(_tokenId, msg.sender); - } - - function _stopMining(uint256 _tokenId) internal { - // remove the miner from land2ResourceMineState; - uint64 minerIndex = miner2Index[_tokenId].indexInResource; - address resource = miner2Index[_tokenId].resource; - uint256 landTokenId = miner2Index[_tokenId].landTokenId; - - // update status! - mine(landTokenId); - - uint64 lastMinerIndex = uint64(land2ResourceMineState[landTokenId].miners[resource].length.sub(1)); - uint256 lastMiner = land2ResourceMineState[landTokenId].miners[resource][lastMinerIndex]; - - land2ResourceMineState[landTokenId].miners[resource][minerIndex] = lastMiner; - land2ResourceMineState[landTokenId].miners[resource][lastMinerIndex] = 0; - - land2ResourceMineState[landTokenId].miners[resource].length -= 1; - miner2Index[lastMiner].indexInResource = minerIndex; - - land2ResourceMineState[landTokenId].totalMiners -= 1; - - address miner = IInterstellarEncoder(registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER)).getObjectAddress(_tokenId); - uint256 strength = IMinerObject(miner).strengthOf(_tokenId, resource, landTokenId); - - // for backward compatibility - // if strength can fluctuate some time in the future - if(land2ResourceMineState[landTokenId].totalMinerStrength[resource] != 0) { - if(land2ResourceMineState[landTokenId].totalMinerStrength[resource] > strength) { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] = land2ResourceMineState[landTokenId].totalMinerStrength[resource].sub(strength); - } else { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] = 0; - } - } - - if(land2ResourceMineState[landTokenId].totalMiners == 0) { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] = 0; - } - - delete miner2Index[_tokenId]; - - emit StopMining(_tokenId, landTokenId, resource, strength); - } - - function getMinerOnLand(uint _landTokenId, address _resourceToken, uint _index) public view returns (uint256) { - return land2ResourceMineState[_landTokenId].miners[_resourceToken][_index]; - } - - function getTotalMiningStrength(uint _landTokenId, address _resourceToken) public view returns (uint256) { - return land2ResourceMineState[_landTokenId].totalMinerStrength[_resourceToken]; - } - - function availableResources(uint256 _landTokenId, address[5] _resourceTokens) public view returns (uint256,uint256,uint256,uint256,uint256) { - - uint availableGold = _calculateMinedBalance(_landTokenId, _resourceTokens[0], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[0]]; - uint availableWood = _calculateMinedBalance(_landTokenId, _resourceTokens[1], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[1]]; - uint availableWater = _calculateMinedBalance(_landTokenId, _resourceTokens[2], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[2]]; - uint availableFire = _calculateMinedBalance(_landTokenId, _resourceTokens[3], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[3]]; - uint availableSoil = _calculateMinedBalance(_landTokenId, _resourceTokens[4], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[4]]; - - return (availableGold, availableWood, availableWater, availableFire, availableSoil); - } - - function mintedBalanceOnLand(uint256 _landTokenId, address _resourceToken) public view returns (uint256) { - return land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken]; - } - -} \ No newline at end of file diff --git a/flat/LandResourceAuthority.sol b/flat/LandResourceAuthority.sol deleted file mode 100644 index 1edb991..0000000 --- a/flat/LandResourceAuthority.sol +++ /dev/null @@ -1,20 +0,0 @@ -// Root file: contracts/LandResourceAuthority.sol - -pragma solidity ^0.4.24; - -contract LandResourceAuthority { - - constructor(address[] _whitelists) public { - for (uint i = 0; i < _whitelists.length; i ++) { - whiteList[_whitelists[i]] = true; - } - } - - mapping (address => bool) public whiteList; - - function canCall( - address _src, address _dst, bytes4 _sig - ) public view returns (bool) { - return ( whiteList[_src] && _sig == bytes4(keccak256("activityStopped(uint256)"))); - } -} \ No newline at end of file diff --git a/flat/LandResourceAuthorityV3.sol b/flat/LandResourceAuthorityV3.sol deleted file mode 100644 index e655528..0000000 --- a/flat/LandResourceAuthorityV3.sol +++ /dev/null @@ -1,22 +0,0 @@ -// Root file: contracts/LandResourceAuthorityV3.sol - -pragma solidity ^0.4.24; - -contract LandResourceAuthorityV3 { - - constructor(address[] _whitelists) public { - for (uint i = 0; i < _whitelists.length; i ++) { - whiteList[_whitelists[i]] = true; - } - } - - mapping (address => bool) public whiteList; - - function canCall( - address _src, address _dst, bytes4 _sig - ) public view returns (bool) { - return ( whiteList[_src] && _sig == bytes4(keccak256("activityStopped(uint256)"))) || - ( whiteList[_src] && _sig == bytes4(keccak256("updateMinerStrengthWhenStop(uint256)"))) || - ( whiteList[_src] && _sig == bytes4(keccak256("updateMinerStrengthWhenStart(uint256)"))); - } -} \ No newline at end of file diff --git a/flat/LandResourceV2.sol b/flat/LandResourceV2.sol deleted file mode 100644 index ae0879b..0000000 --- a/flat/LandResourceV2.sol +++ /dev/null @@ -1,1001 +0,0 @@ -// Dependency file: openzeppelin-solidity/contracts/math/SafeMath.sol - -// pragma solidity ^0.4.24; - - -/** - * @title SafeMath - * @dev Math operations with safety checks that throw on error - */ -library SafeMath { - - /** - * @dev Multiplies two numbers, throws on overflow. - */ - function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) { - // Gas optimization: this is cheaper than asserting 'a' not being zero, but the - // benefit is lost if 'b' is also tested. - // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 - if (_a == 0) { - return 0; - } - - c = _a * _b; - assert(c / _a == _b); - return c; - } - - /** - * @dev Integer division of two numbers, truncating the quotient. - */ - function div(uint256 _a, uint256 _b) internal pure returns (uint256) { - // assert(_b > 0); // Solidity automatically throws when dividing by 0 - // uint256 c = _a / _b; - // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold - return _a / _b; - } - - /** - * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). - */ - function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { - assert(_b <= _a); - return _a - _b; - } - - /** - * @dev Adds two numbers, throws on overflow. - */ - function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) { - c = _a + _b; - assert(c >= _a); - return c; - } -} - - -// Dependency file: openzeppelin-solidity/contracts/introspection/ERC165.sol - -// pragma solidity ^0.4.24; - - -/** - * @title ERC165 - * @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md - */ -interface ERC165 { - - /** - * @notice Query if a contract implements an interface - * @param _interfaceId The interface identifier, as specified in ERC-165 - * @dev Interface identification is specified in ERC-165. This function - * uses less than 30,000 gas. - */ - function supportsInterface(bytes4 _interfaceId) - external - view - returns (bool); -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - - -/** - * @title ERC721 Non-Fungible Token Standard basic interface - * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Basic is ERC165 { - - bytes4 internal constant InterfaceId_ERC721 = 0x80ac58cd; - /* - * 0x80ac58cd === - * bytes4(keccak256('balanceOf(address)')) ^ - * bytes4(keccak256('ownerOf(uint256)')) ^ - * bytes4(keccak256('approve(address,uint256)')) ^ - * bytes4(keccak256('getApproved(uint256)')) ^ - * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ - * bytes4(keccak256('isApprovedForAll(address,address)')) ^ - * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ - * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ - * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) - */ - - bytes4 internal constant InterfaceId_ERC721Exists = 0x4f558e79; - /* - * 0x4f558e79 === - * bytes4(keccak256('exists(uint256)')) - */ - - bytes4 internal constant InterfaceId_ERC721Enumerable = 0x780e9d63; - /** - * 0x780e9d63 === - * bytes4(keccak256('totalSupply()')) ^ - * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) ^ - * bytes4(keccak256('tokenByIndex(uint256)')) - */ - - bytes4 internal constant InterfaceId_ERC721Metadata = 0x5b5e139f; - /** - * 0x5b5e139f === - * bytes4(keccak256('name()')) ^ - * bytes4(keccak256('symbol()')) ^ - * bytes4(keccak256('tokenURI(uint256)')) - */ - - event Transfer( - address indexed _from, - address indexed _to, - uint256 indexed _tokenId - ); - event Approval( - address indexed _owner, - address indexed _approved, - uint256 indexed _tokenId - ); - event ApprovalForAll( - address indexed _owner, - address indexed _operator, - bool _approved - ); - - function balanceOf(address _owner) public view returns (uint256 _balance); - function ownerOf(uint256 _tokenId) public view returns (address _owner); - function exists(uint256 _tokenId) public view returns (bool _exists); - - function approve(address _to, uint256 _tokenId) public; - function getApproved(uint256 _tokenId) - public view returns (address _operator); - - function setApprovalForAll(address _operator, bool _approved) public; - function isApprovedForAll(address _owner, address _operator) - public view returns (bool); - - function transferFrom(address _from, address _to, uint256 _tokenId) public; - function safeTransferFrom(address _from, address _to, uint256 _tokenId) - public; - - function safeTransferFrom( - address _from, - address _to, - uint256 _tokenId, - bytes _data - ) - public; -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol"; - - -/** - * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Enumerable is ERC721Basic { - function totalSupply() public view returns (uint256); - function tokenOfOwnerByIndex( - address _owner, - uint256 _index - ) - public - view - returns (uint256 _tokenId); - - function tokenByIndex(uint256 _index) public view returns (uint256); -} - - -/** - * @title ERC-721 Non-Fungible Token Standard, optional metadata extension - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Metadata is ERC721Basic { - function name() external view returns (string _name); - function symbol() external view returns (string _symbol); - function tokenURI(uint256 _tokenId) public view returns (string); -} - - -/** - * @title ERC-721 Non-Fungible Token Standard, full implementation interface - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721 is ERC721Basic, ERC721Enumerable, ERC721Metadata { -} - - -// Dependency file: openzeppelin-solidity/contracts/introspection/SupportsInterfaceWithLookup.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - - -/** - * @title SupportsInterfaceWithLookup - * @author Matt Condon (@shrugs) - * @dev Implements ERC165 using a lookup table. - */ -contract SupportsInterfaceWithLookup is ERC165 { - - bytes4 public constant InterfaceId_ERC165 = 0x01ffc9a7; - /** - * 0x01ffc9a7 === - * bytes4(keccak256('supportsInterface(bytes4)')) - */ - - /** - * @dev a mapping of interface id to whether or not it's supported - */ - mapping(bytes4 => bool) internal supportedInterfaces; - - /** - * @dev A contract implementing SupportsInterfaceWithLookup - * implement ERC165 itself - */ - constructor() - public - { - _registerInterface(InterfaceId_ERC165); - } - - /** - * @dev implement supportsInterface(bytes4) using a lookup table - */ - function supportsInterface(bytes4 _interfaceId) - external - view - returns (bool) - { - return supportedInterfaces[_interfaceId]; - } - - /** - * @dev private method for registering an interface - */ - function _registerInterface(bytes4 _interfaceId) - internal - { - require(_interfaceId != 0xffffffff); - supportedInterfaces[_interfaceId] = true; - } -} - - -// Dependency file: @evolutionland/common/contracts/interfaces/IMintableERC20.sol - -// pragma solidity ^0.4.23; - -contract IMintableERC20 { - - function mint(address _to, uint256 _value) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/ISettingsRegistry.sol - -// pragma solidity ^0.4.24; - -contract ISettingsRegistry { - enum SettingsValueTypes { NONE, UINT, STRING, ADDRESS, BYTES, BOOL, INT } - - function uintOf(bytes32 _propertyName) public view returns (uint256); - - function stringOf(bytes32 _propertyName) public view returns (string); - - function addressOf(bytes32 _propertyName) public view returns (address); - - function bytesOf(bytes32 _propertyName) public view returns (bytes); - - function boolOf(bytes32 _propertyName) public view returns (bool); - - function intOf(bytes32 _propertyName) public view returns (int); - - function setUintProperty(bytes32 _propertyName, uint _value) public; - - function setStringProperty(bytes32 _propertyName, string _value) public; - - function setAddressProperty(bytes32 _propertyName, address _value) public; - - function setBytesProperty(bytes32 _propertyName, bytes _value) public; - - function setBoolProperty(bytes32 _propertyName, bool _value) public; - - function setIntProperty(bytes32 _propertyName, int _value) public; - - function getValueTypeOf(bytes32 _propertyName) public view returns (uint /* SettingsValueTypes */ ); - - event ChangeProperty(bytes32 indexed _propertyName, uint256 _type); -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IAuthority.sol - -// pragma solidity ^0.4.24; - -contract IAuthority { - function canCall( - address src, address dst, bytes4 sig - ) public view returns (bool); -} - -// Dependency file: @evolutionland/common/contracts/DSAuth.sol - -// pragma solidity ^0.4.24; - -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/IAuthority.sol'; - -contract DSAuthEvents { - event LogSetAuthority (address indexed authority); - event LogSetOwner (address indexed owner); -} - -/** - * @title DSAuth - * @dev The DSAuth contract is reference implement of https://github.com/dapphub/ds-auth - * But in the isAuthorized method, the src from address(this) is remove for safty concern. - */ -contract DSAuth is DSAuthEvents { - IAuthority public authority; - address public owner; - - constructor() public { - owner = msg.sender; - emit LogSetOwner(msg.sender); - } - - function setOwner(address owner_) - public - auth - { - owner = owner_; - emit LogSetOwner(owner); - } - - function setAuthority(IAuthority authority_) - public - auth - { - authority = authority_; - emit LogSetAuthority(authority); - } - - modifier auth { - require(isAuthorized(msg.sender, msg.sig)); - _; - } - - modifier onlyOwner() { - require(msg.sender == owner); - _; - } - - function isAuthorized(address src, bytes4 sig) internal view returns (bool) { - if (src == owner) { - return true; - } else if (authority == IAuthority(0)) { - return false; - } else { - return authority.canCall(src, this, sig); - } - } -} - - -// Dependency file: @evolutionland/common/contracts/SettingIds.sol - -// pragma solidity ^0.4.24; - -/** - Id definitions for SettingsRegistry.sol - Can be used in conjunction with the settings registry to get properties -*/ -contract SettingIds { - bytes32 public constant CONTRACT_RING_ERC20_TOKEN = "CONTRACT_RING_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_KTON_ERC20_TOKEN = "CONTRACT_KTON_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_GOLD_ERC20_TOKEN = "CONTRACT_GOLD_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_WOOD_ERC20_TOKEN = "CONTRACT_WOOD_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_WATER_ERC20_TOKEN = "CONTRACT_WATER_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_FIRE_ERC20_TOKEN = "CONTRACT_FIRE_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_SOIL_ERC20_TOKEN = "CONTRACT_SOIL_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_OBJECT_OWNERSHIP = "CONTRACT_OBJECT_OWNERSHIP"; - - bytes32 public constant CONTRACT_TOKEN_LOCATION = "CONTRACT_TOKEN_LOCATION"; - - bytes32 public constant CONTRACT_LAND_BASE = "CONTRACT_LAND_BASE"; - - bytes32 public constant CONTRACT_USER_POINTS = "CONTRACT_USER_POINTS"; - - bytes32 public constant CONTRACT_INTERSTELLAR_ENCODER = "CONTRACT_INTERSTELLAR_ENCODER"; - - bytes32 public constant CONTRACT_DIVIDENDS_POOL = "CONTRACT_DIVIDENDS_POOL"; - - bytes32 public constant CONTRACT_TOKEN_USE = "CONTRACT_TOKEN_USE"; - - bytes32 public constant CONTRACT_REVENUE_POOL = "CONTRACT_REVENUE_POOL"; - - bytes32 public constant CONTRACT_ERC721_BRIDGE = "CONTRACT_ERC721_BRIDGE"; - - bytes32 public constant CONTRACT_PET_BASE = "CONTRACT_PET_BASE"; - - // Cut owner takes on each auction, measured in basis points (1/100 of a percent). - // this can be considered as transaction fee. - // Values 0-10,000 map to 0%-100% - // set ownerCut to 4% - // ownerCut = 400; - bytes32 public constant UINT_AUCTION_CUT = "UINT_AUCTION_CUT"; // Denominator is 10000 - - bytes32 public constant UINT_TOKEN_OFFER_CUT = "UINT_TOKEN_OFFER_CUT"; // Denominator is 10000 - - // Cut referer takes on each auction, measured in basis points (1/100 of a percent). - // which cut from transaction fee. - // Values 0-10,000 map to 0%-100% - // set refererCut to 4% - // refererCut = 400; - bytes32 public constant UINT_REFERER_CUT = "UINT_REFERER_CUT"; - - bytes32 public constant CONTRACT_LAND_RESOURCE = "CONTRACT_LAND_RESOURCE"; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IInterstellarEncoder.sol - -// pragma solidity ^0.4.24; - -contract IInterstellarEncoder { - uint256 constant CLEAR_HIGH = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff; - - uint256 public constant MAGIC_NUMBER = 42; // Interstellar Encoding Magic Number. - uint256 public constant CHAIN_ID = 1; // Ethereum mainet. - uint256 public constant CURRENT_LAND = 1; // 1 is Atlantis, 0 is NaN. - - enum ObjectClass { - NaN, - LAND, - APOSTLE, - OBJECT_CLASS_COUNT - } - - function registerNewObjectClass(address _objectContract, uint8 objectClass) public; - - function registerNewTokenContract(address _tokenAddress) public; - - function encodeTokenId(address _tokenAddress, uint8 _objectClass, uint128 _objectIndex) public view returns (uint256 _tokenId); - - function encodeTokenIdForObjectContract( - address _tokenAddress, address _objectContract, uint128 _objectId) public view returns (uint256 _tokenId); - - function getContractAddress(uint256 _tokenId) public view returns (address); - - function getObjectId(uint256 _tokenId) public view returns (uint128 _objectId); - - function getObjectClass(uint256 _tokenId) public view returns (uint8); - - function getObjectAddress(uint256 _tokenId) public view returns (address); -} - -// Dependency file: @evolutionland/common/contracts/interfaces/ITokenUse.sol - -// pragma solidity ^0.4.24; - -contract ITokenUse { - uint48 public constant MAX_UINT48_TIME = 281474976710655; - - function isObjectInHireStage(uint256 _tokenId) public view returns (bool); - - function isObjectReadyToUse(uint256 _tokenId) public view returns (bool); - - function getTokenUser(uint256 _tokenId) public view returns (address); - - function createTokenUseOffer(uint256 _tokenId, uint256 _duration, uint256 _price, address _acceptedActivity) public; - - function cancelTokenUseOffer(uint256 _tokenId) public; - - function takeTokenUseOffer(uint256 _tokenId) public; - - function addActivity(uint256 _tokenId, address _user, uint256 _endTime) public; - - function removeActivity(uint256 _tokenId, address _user) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IActivity.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - -contract IActivity is ERC165 { - bytes4 internal constant InterfaceId_IActivity = 0x6086e7f8; - /* - * 0x6086e7f8 === - * bytes4(keccak256('activityStopped(uint256)')) - */ - - function activityStopped(uint256 _tokenId) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IMinerObject.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - -contract IMinerObject is ERC165 { - bytes4 internal constant InterfaceId_IMinerObject = 0x64272b75; - - /* - * 0x64272b752 === - * bytes4(keccak256('strengthOf(uint256,address)')) - */ - - function strengthOf(uint256 _tokenId, address _resourceToken, uint256 _landTokenId) public view returns (uint256); - -} - -// Dependency file: contracts/interfaces/ILandBase.sol - -// pragma solidity ^0.4.24; - -contract ILandBase { - - /* - * Event - */ - event ModifiedResourceRate(uint indexed tokenId, address resourceToken, uint16 newResourceRate); - event HasboxSetted(uint indexed tokenId, bool hasBox); - - event ChangedReourceRateAttr(uint indexed tokenId, uint256 attr); - - event ChangedFlagMask(uint indexed tokenId, uint256 newFlagMask); - - event CreatedNewLand(uint indexed tokenId, int x, int y, address beneficiary, uint256 resourceRateAttr, uint256 mask); - - function defineResouceTokenRateAttrId(address _resourceToken, uint8 _attrId) public; - - function setHasBox(uint _landTokenID, bool isHasBox) public; - function isReserved(uint256 _tokenId) public view returns (bool); - function isSpecial(uint256 _tokenId) public view returns (bool); - function isHasBox(uint256 _tokenId) public view returns (bool); - - function getResourceRateAttr(uint _landTokenId) public view returns (uint256); - function setResourceRateAttr(uint _landTokenId, uint256 _newResourceRateAttr) public; - - function getResourceRate(uint _landTokenId, address _resouceToken) public view returns (uint16); - function setResourceRate(uint _landTokenID, address _resourceToken, uint16 _newResouceRate) public; - - function getFlagMask(uint _landTokenId) public view returns (uint256); - - function setFlagMask(uint _landTokenId, uint256 _newFlagMask) public; - - function resourceToken2RateAttrId(address _resourceToken) external view returns (uint256); -} - - -// Dependency file: contracts/LandSettingIds.sol - -// pragma solidity ^0.4.24; - -// import "@evolutionland/common/contracts/SettingIds.sol"; - -contract LandSettingIds is SettingIds { - -} - -// Root file: contracts/LandResourceV2.sol - -pragma solidity ^0.4.23; - -// import "openzeppelin-solidity/contracts/math/SafeMath.sol"; -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; -// import "openzeppelin-solidity/contracts/introspection/SupportsInterfaceWithLookup.sol"; -// import "@evolutionland/common/contracts/interfaces/IMintableERC20.sol"; -// import "@evolutionland/common/contracts/interfaces/ISettingsRegistry.sol"; -// import "@evolutionland/common/contracts/DSAuth.sol"; -// import "@evolutionland/common/contracts/SettingIds.sol"; -// import "@evolutionland/common/contracts/interfaces/IInterstellarEncoder.sol"; -// import "@evolutionland/common/contracts/interfaces/ITokenUse.sol"; -// import "@evolutionland/common/contracts/interfaces/IActivity.sol"; -// import "@evolutionland/common/contracts/interfaces/IMinerObject.sol"; -// import "contracts/interfaces/ILandBase.sol"; -// import "contracts/LandSettingIds.sol"; - -/** - * @title LandResource - * @dev LandResource is registry that manage the element resources generated on Land, and related resource releasing speed. - */ -contract LandResourceV2 is SupportsInterfaceWithLookup, DSAuth, IActivity, LandSettingIds { - using SafeMath for *; - - // For every seconds, the speed will decrease by current speed multiplying (DENOMINATOR_in_seconds - seconds) / DENOMINATOR_in_seconds - // resource will decrease 1/10000 every day. - uint256 public constant DENOMINATOR = 10000; - - uint256 public constant TOTAL_SECONDS = DENOMINATOR * (1 days); - - bool private singletonLock = false; - - ISettingsRegistry public registry; - - uint256 public resourceReleaseStartTime; - - // TODO: move to global settings contract. - uint256 public attenPerDay = 1; - uint256 public recoverAttenPerDay = 20; - - // Struct for recording resouces on land which have already been pinged. - // 金, Evolution Land Gold - // 木, Evolution Land Wood - // 水, Evolution Land Water - // 火, Evolution Land fire - // 土, Evolution Land Silicon - struct ResourceMineState { - mapping(address => uint256) mintedBalance; - mapping(address => uint256[]) miners; - mapping(address => uint256) totalMinerStrength; - uint256 lastUpdateSpeedInSeconds; - uint256 lastDestoryAttenInSeconds; - uint256 industryIndex; - uint128 lastUpdateTime; - uint64 totalMiners; - uint64 maxMiners; - } - - struct MinerStatus { - uint256 landTokenId; - address resource; - uint64 indexInResource; - } - - mapping(uint256 => ResourceMineState) public land2ResourceMineState; - - mapping(uint256 => MinerStatus) public miner2Index; - - /* - * Event - */ - - event StartMining(uint256 minerTokenId, uint256 landTokenId, address _resource, uint256 strength); - event StopMining(uint256 minerTokenId, uint256 landTokenId, address _resource, uint256 strength); - event ResourceClaimed(address owner, uint256 landTokenId, uint256 goldBalance, uint256 woodBalance, uint256 waterBalance, uint256 fireBalance, uint256 soilBalance); - - /* - * Modifiers - */ - modifier singletonLockCall() { - require(!singletonLock, "Only can call once"); - _; - singletonLock = true; - } - - function initializeContract(address _registry, uint256 _resourceReleaseStartTime) public singletonLockCall { - // Ownable constructor - owner = msg.sender; - emit LogSetOwner(msg.sender); - - registry = ISettingsRegistry(_registry); - - resourceReleaseStartTime = _resourceReleaseStartTime; - - _registerInterface(InterfaceId_IActivity); - } - - // get amount of speed uint at this moment - function _getReleaseSpeedInSeconds(uint256 _tokenId, uint256 _time) internal view returns (uint256 currentSpeed) { - require(_time >= resourceReleaseStartTime, "Should after release time"); - require(_time >= land2ResourceMineState[_tokenId].lastUpdateTime, "Should after release last update time"); - - // after 10000 days from start - // the resource release speed decreases to 0 - if (TOTAL_SECONDS < _time - resourceReleaseStartTime) - { - return 0; - } - - // max amount of speed unit of _tokenId for now - // suppose that speed_uint = 1 in this function - uint256 availableSpeedInSeconds = TOTAL_SECONDS.sub(_time - resourceReleaseStartTime); - // time from last update - uint256 timeBetween = _time - land2ResourceMineState[_tokenId].lastUpdateTime; - - // the recover speed is 20/10000, 20 times. - // recoveryRate overall from lasUpdateTime til now + amount of speed uint at lastUpdateTime - uint256 nextSpeedInSeconds = land2ResourceMineState[_tokenId].lastUpdateSpeedInSeconds + timeBetween * recoverAttenPerDay; - // destroyRate overall from lasUpdateTime til now amount of speed uint at lastUpdateTime - uint256 destroyedSpeedInSeconds = timeBetween * land2ResourceMineState[_tokenId].lastDestoryAttenInSeconds; - - if (nextSpeedInSeconds < destroyedSpeedInSeconds) - { - nextSpeedInSeconds = 0; - } else { - nextSpeedInSeconds = nextSpeedInSeconds - destroyedSpeedInSeconds; - } - - if (nextSpeedInSeconds > availableSpeedInSeconds) { - nextSpeedInSeconds = availableSpeedInSeconds; - } - - return nextSpeedInSeconds; - } - - function getReleaseSpeed(uint256 _tokenId, address _resourceToken, uint256 _time) public view returns (uint256 currentSpeed) { - return ILandBase(registry.addressOf(CONTRACT_LAND_BASE)) - .getResourceRate(_tokenId, _resourceToken).mul(_getReleaseSpeedInSeconds(_tokenId, _time)) - .div(TOTAL_SECONDS); - } - - /** - * @dev Get and Query the amount of resources available from lastUpdateTime to now for use on specific land. - * @param _tokenId The token id of specific land. - */ - function _getMinableBalance(uint256 _tokenId, address _resourceToken, uint256 _currentTime, uint256 _lastUpdateTime) public view returns (uint256 minableBalance) { - - uint256 speed_in_current_period = ILandBase(registry.addressOf(CONTRACT_LAND_BASE)) - .getResourceRate(_tokenId, _resourceToken).mul(_getReleaseSpeedInSeconds(_tokenId, ((_currentTime + _lastUpdateTime) / 2))).mul(1 ether).div(1 days).div(TOTAL_SECONDS); - - // calculate the area of trapezoid - minableBalance = speed_in_current_period.mul(_currentTime - _lastUpdateTime); - } - - function _getMaxMineBalance(uint256 _tokenId, address _resourceToken, uint256 _currentTime, uint256 _lastUpdateTime) internal view returns (uint256) { - // totalMinerStrength is in wei - uint256 mineSpeed = land2ResourceMineState[_tokenId].totalMinerStrength[_resourceToken]; - - return mineSpeed.mul(_currentTime - _lastUpdateTime).div(1 days); - } - - function mine(uint256 _landTokenId) public { - _mineAllResource( - _landTokenId, - registry.addressOf(CONTRACT_GOLD_ERC20_TOKEN), - registry.addressOf(CONTRACT_WOOD_ERC20_TOKEN), - registry.addressOf(CONTRACT_WATER_ERC20_TOKEN), - registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN), - registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN) - ); - } - - function _mineAllResource(uint256 _landTokenId, address _gold, address _wood, address _water, address _fire, address _soil) internal { - require(IInterstellarEncoder(registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER)).getObjectClass(_landTokenId) == 1, "Token must be land."); - - if (land2ResourceMineState[_landTokenId].lastUpdateTime == 0) { - land2ResourceMineState[_landTokenId].lastUpdateTime = uint128(resourceReleaseStartTime); - land2ResourceMineState[_landTokenId].lastUpdateSpeedInSeconds = TOTAL_SECONDS; - } - - _mineResource(_landTokenId, _gold); - _mineResource(_landTokenId, _wood); - _mineResource(_landTokenId, _water); - _mineResource(_landTokenId, _fire); - _mineResource(_landTokenId, _soil); - - land2ResourceMineState[_landTokenId].lastUpdateSpeedInSeconds = _getReleaseSpeedInSeconds(_landTokenId, now); - land2ResourceMineState[_landTokenId].lastUpdateTime = uint128(now); - - } - - function _mineResource(uint256 _landTokenId, address _resourceToken) internal { - // the longest seconds to zero speed. - uint minedBalance = _calculateMinedBalance(_landTokenId, _resourceToken, now); - - land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken] += minedBalance; - } - - function _calculateMinedBalance(uint256 _landTokenId, address _resourceToken, uint256 _currentTime) internal returns (uint256) { - uint256 currentTime = _currentTime; - - uint256 minedBalance; - uint256 minableBalance; - if (currentTime > (resourceReleaseStartTime + TOTAL_SECONDS)) - { - currentTime = (resourceReleaseStartTime + TOTAL_SECONDS); - } - - uint256 lastUpdateTime = land2ResourceMineState[_landTokenId].lastUpdateTime; - require(currentTime >= lastUpdateTime); - - if (lastUpdateTime >= (resourceReleaseStartTime + TOTAL_SECONDS)) { - minedBalance = 0; - minableBalance = 0; - } else { - minedBalance = _getMaxMineBalance(_landTokenId, _resourceToken, currentTime, lastUpdateTime); - minableBalance = _getMinableBalance(_landTokenId, _resourceToken, currentTime, lastUpdateTime); - } - - - if (minedBalance > minableBalance) { - minedBalance = minableBalance; - } - - return minedBalance; - } - - function claimAllResource(uint256 _landTokenId) public { - require(msg.sender == ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(_landTokenId), "Must be the owner of the land"); - - address gold = registry.addressOf(CONTRACT_GOLD_ERC20_TOKEN); - address wood = registry.addressOf(CONTRACT_WOOD_ERC20_TOKEN); - address water = registry.addressOf(CONTRACT_WATER_ERC20_TOKEN); - address fire = registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN); - address soil = registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN); - - _mineAllResource(_landTokenId, gold, wood, water, fire, soil); - - uint goldBalance; - uint woodBalance; - uint waterBalance; - uint fireBalance; - uint soilBalance; - - if (land2ResourceMineState[_landTokenId].mintedBalance[gold] > 0) { - goldBalance = land2ResourceMineState[_landTokenId].mintedBalance[gold]; - IMintableERC20(gold).mint(msg.sender, goldBalance); - land2ResourceMineState[_landTokenId].mintedBalance[gold] = 0; - } - - if (land2ResourceMineState[_landTokenId].mintedBalance[wood] > 0) { - woodBalance = land2ResourceMineState[_landTokenId].mintedBalance[wood]; - IMintableERC20(wood).mint(msg.sender, woodBalance); - land2ResourceMineState[_landTokenId].mintedBalance[wood] = 0; - } - - if (land2ResourceMineState[_landTokenId].mintedBalance[water] > 0) { - waterBalance = land2ResourceMineState[_landTokenId].mintedBalance[water]; - IMintableERC20(water).mint(msg.sender, waterBalance); - land2ResourceMineState[_landTokenId].mintedBalance[water] = 0; - } - - if (land2ResourceMineState[_landTokenId].mintedBalance[fire] > 0) { - fireBalance = land2ResourceMineState[_landTokenId].mintedBalance[fire]; - IMintableERC20(fire).mint(msg.sender, fireBalance); - land2ResourceMineState[_landTokenId].mintedBalance[fire] = 0; - } - - if (land2ResourceMineState[_landTokenId].mintedBalance[soil] > 0) { - soilBalance = land2ResourceMineState[_landTokenId].mintedBalance[soil]; - IMintableERC20(soil).mint(msg.sender, soilBalance); - land2ResourceMineState[_landTokenId].mintedBalance[soil] = 0; - } - - emit ResourceClaimed(msg.sender, _landTokenId, goldBalance, woodBalance, waterBalance, fireBalance, soilBalance); - } - - // both for own _tokenId or hired one - function startMining(uint256 _tokenId, uint256 _landTokenId, address _resource) public { - ITokenUse tokenUse = ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)); - - tokenUse.addActivity(_tokenId, msg.sender, 0); - - // require the permission from land owner; - require(msg.sender == ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(_landTokenId), "Must be the owner of the land"); - - // make sure that _tokenId won't be used repeatedly - require(miner2Index[_tokenId].landTokenId == 0); - - // update status! - mine(_landTokenId); - - uint256 _index = land2ResourceMineState[_landTokenId].miners[_resource].length; - - land2ResourceMineState[_landTokenId].totalMiners += 1; - - if (land2ResourceMineState[_landTokenId].maxMiners == 0) { - land2ResourceMineState[_landTokenId].maxMiners = 5; - } - - require(land2ResourceMineState[_landTokenId].totalMiners <= land2ResourceMineState[_landTokenId].maxMiners); - - address miner = IInterstellarEncoder(registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER)).getObjectAddress(_tokenId); - uint256 strength = IMinerObject(miner).strengthOf(_tokenId, _resource, _landTokenId); - - land2ResourceMineState[_landTokenId].miners[_resource].push(_tokenId); - land2ResourceMineState[_landTokenId].totalMinerStrength[_resource] += strength; - - miner2Index[_tokenId] = MinerStatus({ - landTokenId : _landTokenId, - resource : _resource, - indexInResource : uint64(_index) - }); - - emit StartMining(_tokenId, _landTokenId, _resource, strength); - - } - - function batchStartMining(uint256[] _tokenIds, uint256[] _landTokenIds, address[] _resources) public { - require(_tokenIds.length == _landTokenIds.length && _landTokenIds.length == _resources.length, "input error"); - uint length = _tokenIds.length; - - for (uint i = 0; i < length; i++) { - startMining(_tokenIds[i], _landTokenIds[i], _resources[i]); - } - - } - - // Only trigger from Token Activity. - function activityStopped(uint256 _tokenId) public auth { - - _stopMining(_tokenId); - } - - function stopMining(uint256 _tokenId) public { - ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).removeActivity(_tokenId, msg.sender); - } - - function _stopMining(uint256 _tokenId) internal { - // remove the miner from land2ResourceMineState; - uint64 minerIndex = miner2Index[_tokenId].indexInResource; - address resource = miner2Index[_tokenId].resource; - uint256 landTokenId = miner2Index[_tokenId].landTokenId; - - // update status! - mine(landTokenId); - - uint64 lastMinerIndex = uint64(land2ResourceMineState[landTokenId].miners[resource].length.sub(1)); - uint256 lastMiner = land2ResourceMineState[landTokenId].miners[resource][lastMinerIndex]; - - land2ResourceMineState[landTokenId].miners[resource][minerIndex] = lastMiner; - land2ResourceMineState[landTokenId].miners[resource][lastMinerIndex] = 0; - - land2ResourceMineState[landTokenId].miners[resource].length -= 1; - miner2Index[lastMiner].indexInResource = minerIndex; - - land2ResourceMineState[landTokenId].totalMiners -= 1; - - address miner = IInterstellarEncoder(registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER)).getObjectAddress(_tokenId); - uint256 strength = IMinerObject(miner).strengthOf(_tokenId, resource, landTokenId); - - // for backward compatibility - // if strength can fluctuate some time in the future - if(land2ResourceMineState[landTokenId].totalMinerStrength[resource] != 0) { - if(land2ResourceMineState[landTokenId].totalMinerStrength[resource] > strength) { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] = land2ResourceMineState[landTokenId].totalMinerStrength[resource].sub(strength); - } else { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] = 0; - } - } - - if(land2ResourceMineState[landTokenId].totalMiners == 0) { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] = 0; - } - - delete miner2Index[_tokenId]; - - emit StopMining(_tokenId, landTokenId, resource, strength); - } - - function getMinerOnLand(uint _landTokenId, address _resourceToken, uint _index) public view returns (uint256) { - return land2ResourceMineState[_landTokenId].miners[_resourceToken][_index]; - } - - function getTotalMiningStrength(uint _landTokenId, address _resourceToken) public view returns (uint256) { - return land2ResourceMineState[_landTokenId].totalMinerStrength[_resourceToken]; - } - - function availableResources(uint256 _landTokenId, address[5] _resourceTokens) public view returns (uint256,uint256,uint256,uint256,uint256) { - - uint availableGold = _calculateMinedBalance(_landTokenId, _resourceTokens[0], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[0]]; - uint availableWood = _calculateMinedBalance(_landTokenId, _resourceTokens[1], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[1]]; - uint availableWater = _calculateMinedBalance(_landTokenId, _resourceTokens[2], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[2]]; - uint availableFire = _calculateMinedBalance(_landTokenId, _resourceTokens[3], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[3]]; - uint availableSoil = _calculateMinedBalance(_landTokenId, _resourceTokens[4], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[4]]; - - return (availableGold, availableWood, availableWater, availableFire, availableSoil); - } - - function mintedBalanceOnLand(uint256 _landTokenId, address _resourceToken) public view returns (uint256) { - return land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken]; - } - -} \ No newline at end of file diff --git a/flat/LandResourceV3.sol b/flat/LandResourceV3.sol deleted file mode 100644 index 24e0db8..0000000 --- a/flat/LandResourceV3.sol +++ /dev/null @@ -1,1060 +0,0 @@ -// Dependency file: openzeppelin-solidity/contracts/math/SafeMath.sol - -// pragma solidity ^0.4.24; - - -/** - * @title SafeMath - * @dev Math operations with safety checks that throw on error - */ -library SafeMath { - - /** - * @dev Multiplies two numbers, throws on overflow. - */ - function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) { - // Gas optimization: this is cheaper than asserting 'a' not being zero, but the - // benefit is lost if 'b' is also tested. - // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 - if (_a == 0) { - return 0; - } - - c = _a * _b; - assert(c / _a == _b); - return c; - } - - /** - * @dev Integer division of two numbers, truncating the quotient. - */ - function div(uint256 _a, uint256 _b) internal pure returns (uint256) { - // assert(_b > 0); // Solidity automatically throws when dividing by 0 - // uint256 c = _a / _b; - // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold - return _a / _b; - } - - /** - * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). - */ - function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { - assert(_b <= _a); - return _a - _b; - } - - /** - * @dev Adds two numbers, throws on overflow. - */ - function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) { - c = _a + _b; - assert(c >= _a); - return c; - } -} - - -// Dependency file: openzeppelin-solidity/contracts/introspection/ERC165.sol - -// pragma solidity ^0.4.24; - - -/** - * @title ERC165 - * @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md - */ -interface ERC165 { - - /** - * @notice Query if a contract implements an interface - * @param _interfaceId The interface identifier, as specified in ERC-165 - * @dev Interface identification is specified in ERC-165. This function - * uses less than 30,000 gas. - */ - function supportsInterface(bytes4 _interfaceId) - external - view - returns (bool); -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - - -/** - * @title ERC721 Non-Fungible Token Standard basic interface - * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Basic is ERC165 { - - bytes4 internal constant InterfaceId_ERC721 = 0x80ac58cd; - /* - * 0x80ac58cd === - * bytes4(keccak256('balanceOf(address)')) ^ - * bytes4(keccak256('ownerOf(uint256)')) ^ - * bytes4(keccak256('approve(address,uint256)')) ^ - * bytes4(keccak256('getApproved(uint256)')) ^ - * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ - * bytes4(keccak256('isApprovedForAll(address,address)')) ^ - * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ - * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ - * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) - */ - - bytes4 internal constant InterfaceId_ERC721Exists = 0x4f558e79; - /* - * 0x4f558e79 === - * bytes4(keccak256('exists(uint256)')) - */ - - bytes4 internal constant InterfaceId_ERC721Enumerable = 0x780e9d63; - /** - * 0x780e9d63 === - * bytes4(keccak256('totalSupply()')) ^ - * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) ^ - * bytes4(keccak256('tokenByIndex(uint256)')) - */ - - bytes4 internal constant InterfaceId_ERC721Metadata = 0x5b5e139f; - /** - * 0x5b5e139f === - * bytes4(keccak256('name()')) ^ - * bytes4(keccak256('symbol()')) ^ - * bytes4(keccak256('tokenURI(uint256)')) - */ - - event Transfer( - address indexed _from, - address indexed _to, - uint256 indexed _tokenId - ); - event Approval( - address indexed _owner, - address indexed _approved, - uint256 indexed _tokenId - ); - event ApprovalForAll( - address indexed _owner, - address indexed _operator, - bool _approved - ); - - function balanceOf(address _owner) public view returns (uint256 _balance); - function ownerOf(uint256 _tokenId) public view returns (address _owner); - function exists(uint256 _tokenId) public view returns (bool _exists); - - function approve(address _to, uint256 _tokenId) public; - function getApproved(uint256 _tokenId) - public view returns (address _operator); - - function setApprovalForAll(address _operator, bool _approved) public; - function isApprovedForAll(address _owner, address _operator) - public view returns (bool); - - function transferFrom(address _from, address _to, uint256 _tokenId) public; - function safeTransferFrom(address _from, address _to, uint256 _tokenId) - public; - - function safeTransferFrom( - address _from, - address _to, - uint256 _tokenId, - bytes _data - ) - public; -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol"; - - -/** - * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Enumerable is ERC721Basic { - function totalSupply() public view returns (uint256); - function tokenOfOwnerByIndex( - address _owner, - uint256 _index - ) - public - view - returns (uint256 _tokenId); - - function tokenByIndex(uint256 _index) public view returns (uint256); -} - - -/** - * @title ERC-721 Non-Fungible Token Standard, optional metadata extension - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Metadata is ERC721Basic { - function name() external view returns (string _name); - function symbol() external view returns (string _symbol); - function tokenURI(uint256 _tokenId) public view returns (string); -} - - -/** - * @title ERC-721 Non-Fungible Token Standard, full implementation interface - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721 is ERC721Basic, ERC721Enumerable, ERC721Metadata { -} - - -// Dependency file: openzeppelin-solidity/contracts/introspection/SupportsInterfaceWithLookup.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - - -/** - * @title SupportsInterfaceWithLookup - * @author Matt Condon (@shrugs) - * @dev Implements ERC165 using a lookup table. - */ -contract SupportsInterfaceWithLookup is ERC165 { - - bytes4 public constant InterfaceId_ERC165 = 0x01ffc9a7; - /** - * 0x01ffc9a7 === - * bytes4(keccak256('supportsInterface(bytes4)')) - */ - - /** - * @dev a mapping of interface id to whether or not it's supported - */ - mapping(bytes4 => bool) internal supportedInterfaces; - - /** - * @dev A contract implementing SupportsInterfaceWithLookup - * implement ERC165 itself - */ - constructor() - public - { - _registerInterface(InterfaceId_ERC165); - } - - /** - * @dev implement supportsInterface(bytes4) using a lookup table - */ - function supportsInterface(bytes4 _interfaceId) - external - view - returns (bool) - { - return supportedInterfaces[_interfaceId]; - } - - /** - * @dev private method for registering an interface - */ - function _registerInterface(bytes4 _interfaceId) - internal - { - require(_interfaceId != 0xffffffff); - supportedInterfaces[_interfaceId] = true; - } -} - - -// Dependency file: @evolutionland/common/contracts/interfaces/IMintableERC20.sol - -// pragma solidity ^0.4.23; - -contract IMintableERC20 { - - function mint(address _to, uint256 _value) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/ISettingsRegistry.sol - -// pragma solidity ^0.4.24; - -contract ISettingsRegistry { - enum SettingsValueTypes { NONE, UINT, STRING, ADDRESS, BYTES, BOOL, INT } - - function uintOf(bytes32 _propertyName) public view returns (uint256); - - function stringOf(bytes32 _propertyName) public view returns (string); - - function addressOf(bytes32 _propertyName) public view returns (address); - - function bytesOf(bytes32 _propertyName) public view returns (bytes); - - function boolOf(bytes32 _propertyName) public view returns (bool); - - function intOf(bytes32 _propertyName) public view returns (int); - - function setUintProperty(bytes32 _propertyName, uint _value) public; - - function setStringProperty(bytes32 _propertyName, string _value) public; - - function setAddressProperty(bytes32 _propertyName, address _value) public; - - function setBytesProperty(bytes32 _propertyName, bytes _value) public; - - function setBoolProperty(bytes32 _propertyName, bool _value) public; - - function setIntProperty(bytes32 _propertyName, int _value) public; - - function getValueTypeOf(bytes32 _propertyName) public view returns (uint /* SettingsValueTypes */ ); - - event ChangeProperty(bytes32 indexed _propertyName, uint256 _type); -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IAuthority.sol - -// pragma solidity ^0.4.24; - -contract IAuthority { - function canCall( - address src, address dst, bytes4 sig - ) public view returns (bool); -} - -// Dependency file: @evolutionland/common/contracts/DSAuth.sol - -// pragma solidity ^0.4.24; - -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/IAuthority.sol'; - -contract DSAuthEvents { - event LogSetAuthority (address indexed authority); - event LogSetOwner (address indexed owner); -} - -/** - * @title DSAuth - * @dev The DSAuth contract is reference implement of https://github.com/dapphub/ds-auth - * But in the isAuthorized method, the src from address(this) is remove for safty concern. - */ -contract DSAuth is DSAuthEvents { - IAuthority public authority; - address public owner; - - constructor() public { - owner = msg.sender; - emit LogSetOwner(msg.sender); - } - - function setOwner(address owner_) - public - auth - { - owner = owner_; - emit LogSetOwner(owner); - } - - function setAuthority(IAuthority authority_) - public - auth - { - authority = authority_; - emit LogSetAuthority(authority); - } - - modifier auth { - require(isAuthorized(msg.sender, msg.sig)); - _; - } - - modifier onlyOwner() { - require(msg.sender == owner); - _; - } - - function isAuthorized(address src, bytes4 sig) internal view returns (bool) { - if (src == owner) { - return true; - } else if (authority == IAuthority(0)) { - return false; - } else { - return authority.canCall(src, this, sig); - } - } -} - - -// Dependency file: @evolutionland/common/contracts/SettingIds.sol - -// pragma solidity ^0.4.24; - -/** - Id definitions for SettingsRegistry.sol - Can be used in conjunction with the settings registry to get properties -*/ -contract SettingIds { - bytes32 public constant CONTRACT_RING_ERC20_TOKEN = "CONTRACT_RING_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_KTON_ERC20_TOKEN = "CONTRACT_KTON_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_GOLD_ERC20_TOKEN = "CONTRACT_GOLD_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_WOOD_ERC20_TOKEN = "CONTRACT_WOOD_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_WATER_ERC20_TOKEN = "CONTRACT_WATER_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_FIRE_ERC20_TOKEN = "CONTRACT_FIRE_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_SOIL_ERC20_TOKEN = "CONTRACT_SOIL_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_OBJECT_OWNERSHIP = "CONTRACT_OBJECT_OWNERSHIP"; - - bytes32 public constant CONTRACT_TOKEN_LOCATION = "CONTRACT_TOKEN_LOCATION"; - - bytes32 public constant CONTRACT_LAND_BASE = "CONTRACT_LAND_BASE"; - - bytes32 public constant CONTRACT_USER_POINTS = "CONTRACT_USER_POINTS"; - - bytes32 public constant CONTRACT_INTERSTELLAR_ENCODER = "CONTRACT_INTERSTELLAR_ENCODER"; - - bytes32 public constant CONTRACT_DIVIDENDS_POOL = "CONTRACT_DIVIDENDS_POOL"; - - bytes32 public constant CONTRACT_TOKEN_USE = "CONTRACT_TOKEN_USE"; - - bytes32 public constant CONTRACT_REVENUE_POOL = "CONTRACT_REVENUE_POOL"; - - bytes32 public constant CONTRACT_ERC721_BRIDGE = "CONTRACT_ERC721_BRIDGE"; - - bytes32 public constant CONTRACT_PET_BASE = "CONTRACT_PET_BASE"; - - // Cut owner takes on each auction, measured in basis points (1/100 of a percent). - // this can be considered as transaction fee. - // Values 0-10,000 map to 0%-100% - // set ownerCut to 4% - // ownerCut = 400; - bytes32 public constant UINT_AUCTION_CUT = "UINT_AUCTION_CUT"; // Denominator is 10000 - - bytes32 public constant UINT_TOKEN_OFFER_CUT = "UINT_TOKEN_OFFER_CUT"; // Denominator is 10000 - - // Cut referer takes on each auction, measured in basis points (1/100 of a percent). - // which cut from transaction fee. - // Values 0-10,000 map to 0%-100% - // set refererCut to 4% - // refererCut = 400; - bytes32 public constant UINT_REFERER_CUT = "UINT_REFERER_CUT"; - - bytes32 public constant CONTRACT_LAND_RESOURCE = "CONTRACT_LAND_RESOURCE"; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IInterstellarEncoder.sol - -// pragma solidity ^0.4.24; - -contract IInterstellarEncoder { - uint256 constant CLEAR_HIGH = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff; - - uint256 public constant MAGIC_NUMBER = 42; // Interstellar Encoding Magic Number. - uint256 public constant CHAIN_ID = 1; // Ethereum mainet. - uint256 public constant CURRENT_LAND = 1; // 1 is Atlantis, 0 is NaN. - - enum ObjectClass { - NaN, - LAND, - APOSTLE, - OBJECT_CLASS_COUNT - } - - function registerNewObjectClass(address _objectContract, uint8 objectClass) public; - - function registerNewTokenContract(address _tokenAddress) public; - - function encodeTokenId(address _tokenAddress, uint8 _objectClass, uint128 _objectIndex) public view returns (uint256 _tokenId); - - function encodeTokenIdForObjectContract( - address _tokenAddress, address _objectContract, uint128 _objectId) public view returns (uint256 _tokenId); - - function getContractAddress(uint256 _tokenId) public view returns (address); - - function getObjectId(uint256 _tokenId) public view returns (uint128 _objectId); - - function getObjectClass(uint256 _tokenId) public view returns (uint8); - - function getObjectAddress(uint256 _tokenId) public view returns (address); -} - -// Dependency file: @evolutionland/common/contracts/interfaces/ITokenUse.sol - -// pragma solidity ^0.4.24; - -contract ITokenUse { - uint48 public constant MAX_UINT48_TIME = 281474976710655; - - function isObjectInHireStage(uint256 _tokenId) public view returns (bool); - - function isObjectReadyToUse(uint256 _tokenId) public view returns (bool); - - function getTokenUser(uint256 _tokenId) public view returns (address); - - function createTokenUseOffer(uint256 _tokenId, uint256 _duration, uint256 _price, address _acceptedActivity) public; - - function cancelTokenUseOffer(uint256 _tokenId) public; - - function takeTokenUseOffer(uint256 _tokenId) public; - - function addActivity(uint256 _tokenId, address _user, uint256 _endTime) public; - - function removeActivity(uint256 _tokenId, address _user) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IActivity.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - -contract IActivity is ERC165 { - bytes4 internal constant InterfaceId_IActivity = 0x6086e7f8; - /* - * 0x6086e7f8 === - * bytes4(keccak256('activityStopped(uint256)')) - */ - - function activityStopped(uint256 _tokenId) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IMinerObject.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - -contract IMinerObject is ERC165 { - bytes4 internal constant InterfaceId_IMinerObject = 0x64272b75; - - /* - * 0x64272b752 === - * bytes4(keccak256('strengthOf(uint256,address)')) - */ - - function strengthOf(uint256 _tokenId, address _resourceToken, uint256 _landTokenId) public view returns (uint256); - -} - -// Dependency file: contracts/interfaces/ILandBase.sol - -// pragma solidity ^0.4.24; - -contract ILandBase { - - /* - * Event - */ - event ModifiedResourceRate(uint indexed tokenId, address resourceToken, uint16 newResourceRate); - event HasboxSetted(uint indexed tokenId, bool hasBox); - - event ChangedReourceRateAttr(uint indexed tokenId, uint256 attr); - - event ChangedFlagMask(uint indexed tokenId, uint256 newFlagMask); - - event CreatedNewLand(uint indexed tokenId, int x, int y, address beneficiary, uint256 resourceRateAttr, uint256 mask); - - function defineResouceTokenRateAttrId(address _resourceToken, uint8 _attrId) public; - - function setHasBox(uint _landTokenID, bool isHasBox) public; - function isReserved(uint256 _tokenId) public view returns (bool); - function isSpecial(uint256 _tokenId) public view returns (bool); - function isHasBox(uint256 _tokenId) public view returns (bool); - - function getResourceRateAttr(uint _landTokenId) public view returns (uint256); - function setResourceRateAttr(uint _landTokenId, uint256 _newResourceRateAttr) public; - - function getResourceRate(uint _landTokenId, address _resouceToken) public view returns (uint16); - function setResourceRate(uint _landTokenID, address _resourceToken, uint16 _newResouceRate) public; - - function getFlagMask(uint _landTokenId) public view returns (uint256); - - function setFlagMask(uint _landTokenId, uint256 _newFlagMask) public; - - function resourceToken2RateAttrId(address _resourceToken) external view returns (uint256); -} - - -// Dependency file: contracts/LandSettingIds.sol - -// pragma solidity ^0.4.24; - -// import "@evolutionland/common/contracts/SettingIds.sol"; - -contract LandSettingIds is SettingIds { - -} - -// Root file: contracts/LandResourceV3.sol - -pragma solidity ^0.4.23; - -// import "openzeppelin-solidity/contracts/math/SafeMath.sol"; -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; -// import "openzeppelin-solidity/contracts/introspection/SupportsInterfaceWithLookup.sol"; -// import "@evolutionland/common/contracts/interfaces/IMintableERC20.sol"; -// import "@evolutionland/common/contracts/interfaces/ISettingsRegistry.sol"; -// import "@evolutionland/common/contracts/DSAuth.sol"; -// import "@evolutionland/common/contracts/SettingIds.sol"; -// import "@evolutionland/common/contracts/interfaces/IInterstellarEncoder.sol"; -// import "@evolutionland/common/contracts/interfaces/ITokenUse.sol"; -// import "@evolutionland/common/contracts/interfaces/IActivity.sol"; -// import "@evolutionland/common/contracts/interfaces/IMinerObject.sol"; -// import "contracts/interfaces/ILandBase.sol"; -// import "contracts/LandSettingIds.sol"; - -/** - * @title LandResource - * @dev LandResource is registry that manage the element resources generated on Land, and related resource releasing speed. - * difference between LandResourceV2: - 1. add function landWorkingOn to get which land the apostle is working on - 2. add function updateMinerStrength to update miner strength on land - 3. add event UpdateMiningStrength - */ - - -contract LandResourceV3 is SupportsInterfaceWithLookup, DSAuth, IActivity, LandSettingIds { - using SafeMath for *; - - // For every seconds, the speed will decrease by current speed multiplying (DENOMINATOR_in_seconds - seconds) / DENOMINATOR_in_seconds - // resource will decrease 1/10000 every day. - uint256 public constant DENOMINATOR = 10000; - - uint256 public constant TOTAL_SECONDS = DENOMINATOR * (1 days); - - bool private singletonLock = false; - - ISettingsRegistry public registry; - - uint256 public resourceReleaseStartTime; - - // TODO: move to global settings contract. - uint256 public attenPerDay = 1; - uint256 public recoverAttenPerDay = 20; - - // Struct for recording resouces on land which have already been pinged. - // 金, Evolution Land Gold - // 木, Evolution Land Wood - // 水, Evolution Land Water - // 火, Evolution Land fire - // 土, Evolution Land Silicon - struct ResourceMineState { - mapping(address => uint256) mintedBalance; - mapping(address => uint256[]) miners; - mapping(address => uint256) totalMinerStrength; - uint256 lastUpdateSpeedInSeconds; - uint256 lastDestoryAttenInSeconds; - uint256 industryIndex; - uint128 lastUpdateTime; - uint64 totalMiners; - uint64 maxMiners; - } - - struct MinerStatus { - uint256 landTokenId; - address resource; - uint64 indexInResource; - } - - mapping(uint256 => ResourceMineState) public land2ResourceMineState; - - mapping(uint256 => MinerStatus) public miner2Index; - - /* - * Event - */ - - event StartMining(uint256 minerTokenId, uint256 landTokenId, address _resource, uint256 strength); - event StopMining(uint256 minerTokenId, uint256 landTokenId, address _resource, uint256 strength); - event ResourceClaimed(address owner, uint256 landTokenId, uint256 goldBalance, uint256 woodBalance, uint256 waterBalance, uint256 fireBalance, uint256 soilBalance); - - event UpdateMiningStrengthWhenStop(uint256 apostleTokenId, uint256 landTokenId, uint256 strength); - event UpdateMiningStrengthWhenStart(uint256 apostleTokenId, uint256 landTokenId, uint256 strength); - /* - * Modifiers - */ - modifier singletonLockCall() { - require(!singletonLock, "Only can call once"); - _; - singletonLock = true; - } - - - function initializeContract(address _registry, uint256 _resourceReleaseStartTime) public singletonLockCall { - // Ownable constructor - owner = msg.sender; - emit LogSetOwner(msg.sender); - - registry = ISettingsRegistry(_registry); - - resourceReleaseStartTime = _resourceReleaseStartTime; - - _registerInterface(InterfaceId_IActivity); - } - - // get amount of speed uint at this moment - function _getReleaseSpeedInSeconds(uint256 _tokenId, uint256 _time) internal view returns (uint256 currentSpeed) { - require(_time >= resourceReleaseStartTime, "Should after release time"); - require(_time >= land2ResourceMineState[_tokenId].lastUpdateTime, "Should after release last update time"); - - // after 10000 days from start - // the resource release speed decreases to 0 - if (TOTAL_SECONDS < _time - resourceReleaseStartTime) - { - return 0; - } - - // max amount of speed unit of _tokenId for now - // suppose that speed_uint = 1 in this function - uint256 availableSpeedInSeconds = TOTAL_SECONDS.sub(_time - resourceReleaseStartTime); - // time from last update - uint256 timeBetween = _time - land2ResourceMineState[_tokenId].lastUpdateTime; - - // the recover speed is 20/10000, 20 times. - // recoveryRate overall from lasUpdateTime til now + amount of speed uint at lastUpdateTime - uint256 nextSpeedInSeconds = land2ResourceMineState[_tokenId].lastUpdateSpeedInSeconds + timeBetween * recoverAttenPerDay; - // destroyRate overall from lasUpdateTime til now amount of speed uint at lastUpdateTime - uint256 destroyedSpeedInSeconds = timeBetween * land2ResourceMineState[_tokenId].lastDestoryAttenInSeconds; - - if (nextSpeedInSeconds < destroyedSpeedInSeconds) - { - nextSpeedInSeconds = 0; - } else { - nextSpeedInSeconds = nextSpeedInSeconds - destroyedSpeedInSeconds; - } - - if (nextSpeedInSeconds > availableSpeedInSeconds) { - nextSpeedInSeconds = availableSpeedInSeconds; - } - - return nextSpeedInSeconds; - } - - function getReleaseSpeed(uint256 _tokenId, address _resourceToken, uint256 _time) public view returns (uint256 currentSpeed) { - return ILandBase(registry.addressOf(CONTRACT_LAND_BASE)) - .getResourceRate(_tokenId, _resourceToken).mul(_getReleaseSpeedInSeconds(_tokenId, _time)) - .div(TOTAL_SECONDS); - } - - /** - * @dev Get and Query the amount of resources available from lastUpdateTime to now for use on specific land. - * @param _tokenId The token id of specific land. - */ - function _getMinableBalance(uint256 _tokenId, address _resourceToken, uint256 _currentTime, uint256 _lastUpdateTime) public view returns (uint256 minableBalance) { - - uint256 speed_in_current_period = ILandBase(registry.addressOf(CONTRACT_LAND_BASE)) - .getResourceRate(_tokenId, _resourceToken).mul(_getReleaseSpeedInSeconds(_tokenId, ((_currentTime + _lastUpdateTime) / 2))).mul(1 ether).div(1 days).div(TOTAL_SECONDS); - - // calculate the area of trapezoid - minableBalance = speed_in_current_period.mul(_currentTime - _lastUpdateTime); - } - - function _getMaxMineBalance(uint256 _tokenId, address _resourceToken, uint256 _currentTime, uint256 _lastUpdateTime) internal view returns (uint256) { - // totalMinerStrength is in wei - uint256 mineSpeed = land2ResourceMineState[_tokenId].totalMinerStrength[_resourceToken]; - - return mineSpeed.mul(_currentTime - _lastUpdateTime).div(1 days); - } - - function mine(uint256 _landTokenId) public { - _mineAllResource( - _landTokenId, - registry.addressOf(CONTRACT_GOLD_ERC20_TOKEN), - registry.addressOf(CONTRACT_WOOD_ERC20_TOKEN), - registry.addressOf(CONTRACT_WATER_ERC20_TOKEN), - registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN), - registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN) - ); - } - - function _mineAllResource(uint256 _landTokenId, address _gold, address _wood, address _water, address _fire, address _soil) internal { - require(IInterstellarEncoder(registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER)).getObjectClass(_landTokenId) == 1, "Token must be land."); - - if (land2ResourceMineState[_landTokenId].lastUpdateTime == 0) { - land2ResourceMineState[_landTokenId].lastUpdateTime = uint128(resourceReleaseStartTime); - land2ResourceMineState[_landTokenId].lastUpdateSpeedInSeconds = TOTAL_SECONDS; - } - - _mineResource(_landTokenId, _gold); - _mineResource(_landTokenId, _wood); - _mineResource(_landTokenId, _water); - _mineResource(_landTokenId, _fire); - _mineResource(_landTokenId, _soil); - - land2ResourceMineState[_landTokenId].lastUpdateSpeedInSeconds = _getReleaseSpeedInSeconds(_landTokenId, now); - land2ResourceMineState[_landTokenId].lastUpdateTime = uint128(now); - - } - - function _mineResource(uint256 _landTokenId, address _resourceToken) internal { - // the longest seconds to zero speed. - uint minedBalance = _calculateMinedBalance(_landTokenId, _resourceToken, now); - - land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken] += minedBalance; - } - - function _calculateMinedBalance(uint256 _landTokenId, address _resourceToken, uint256 _currentTime) internal returns (uint256) { - uint256 currentTime = _currentTime; - - uint256 minedBalance; - uint256 minableBalance; - if (currentTime > (resourceReleaseStartTime + TOTAL_SECONDS)) - { - currentTime = (resourceReleaseStartTime + TOTAL_SECONDS); - } - - uint256 lastUpdateTime = land2ResourceMineState[_landTokenId].lastUpdateTime; - require(currentTime >= lastUpdateTime); - - if (lastUpdateTime >= (resourceReleaseStartTime + TOTAL_SECONDS)) { - minedBalance = 0; - minableBalance = 0; - } else { - minedBalance = _getMaxMineBalance(_landTokenId, _resourceToken, currentTime, lastUpdateTime); - minableBalance = _getMinableBalance(_landTokenId, _resourceToken, currentTime, lastUpdateTime); - } - - - if (minedBalance > minableBalance) { - minedBalance = minableBalance; - } - - return minedBalance; - } - - function claimAllResource(uint256 _landTokenId) public { - require(msg.sender == ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(_landTokenId), "Must be the owner of the land"); - - address gold = registry.addressOf(CONTRACT_GOLD_ERC20_TOKEN); - address wood = registry.addressOf(CONTRACT_WOOD_ERC20_TOKEN); - address water = registry.addressOf(CONTRACT_WATER_ERC20_TOKEN); - address fire = registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN); - address soil = registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN); - - _mineAllResource(_landTokenId, gold, wood, water, fire, soil); - - uint goldBalance; - uint woodBalance; - uint waterBalance; - uint fireBalance; - uint soilBalance; - - if (land2ResourceMineState[_landTokenId].mintedBalance[gold] > 0) { - goldBalance = land2ResourceMineState[_landTokenId].mintedBalance[gold]; - IMintableERC20(gold).mint(msg.sender, goldBalance); - land2ResourceMineState[_landTokenId].mintedBalance[gold] = 0; - } - - if (land2ResourceMineState[_landTokenId].mintedBalance[wood] > 0) { - woodBalance = land2ResourceMineState[_landTokenId].mintedBalance[wood]; - IMintableERC20(wood).mint(msg.sender, woodBalance); - land2ResourceMineState[_landTokenId].mintedBalance[wood] = 0; - } - - if (land2ResourceMineState[_landTokenId].mintedBalance[water] > 0) { - waterBalance = land2ResourceMineState[_landTokenId].mintedBalance[water]; - IMintableERC20(water).mint(msg.sender, waterBalance); - land2ResourceMineState[_landTokenId].mintedBalance[water] = 0; - } - - if (land2ResourceMineState[_landTokenId].mintedBalance[fire] > 0) { - fireBalance = land2ResourceMineState[_landTokenId].mintedBalance[fire]; - IMintableERC20(fire).mint(msg.sender, fireBalance); - land2ResourceMineState[_landTokenId].mintedBalance[fire] = 0; - } - - if (land2ResourceMineState[_landTokenId].mintedBalance[soil] > 0) { - soilBalance = land2ResourceMineState[_landTokenId].mintedBalance[soil]; - IMintableERC20(soil).mint(msg.sender, soilBalance); - land2ResourceMineState[_landTokenId].mintedBalance[soil] = 0; - } - - emit ResourceClaimed(msg.sender, _landTokenId, goldBalance, woodBalance, waterBalance, fireBalance, soilBalance); - } - - // both for own _tokenId or hired one - function startMining(uint256 _tokenId, uint256 _landTokenId, address _resource) public { - ITokenUse tokenUse = ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)); - - tokenUse.addActivity(_tokenId, msg.sender, 0); - - // require the permission from land owner; - require(msg.sender == ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(_landTokenId), "Must be the owner of the land"); - - // make sure that _tokenId won't be used repeatedly - require(miner2Index[_tokenId].landTokenId == 0); - - // update status! - mine(_landTokenId); - - uint256 _index = land2ResourceMineState[_landTokenId].miners[_resource].length; - - land2ResourceMineState[_landTokenId].totalMiners += 1; - - if (land2ResourceMineState[_landTokenId].maxMiners == 0) { - land2ResourceMineState[_landTokenId].maxMiners = 5; - } - - require(land2ResourceMineState[_landTokenId].totalMiners <= land2ResourceMineState[_landTokenId].maxMiners); - - address miner = IInterstellarEncoder(registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER)).getObjectAddress(_tokenId); - uint256 strength = IMinerObject(miner).strengthOf(_tokenId, _resource, _landTokenId); - - land2ResourceMineState[_landTokenId].miners[_resource].push(_tokenId); - land2ResourceMineState[_landTokenId].totalMinerStrength[_resource] += strength; - - miner2Index[_tokenId] = MinerStatus({ - landTokenId : _landTokenId, - resource : _resource, - indexInResource : uint64(_index) - }); - - emit StartMining(_tokenId, _landTokenId, _resource, strength); - - } - - function batchStartMining(uint256[] _tokenIds, uint256[] _landTokenIds, address[] _resources) public { - require(_tokenIds.length == _landTokenIds.length && _landTokenIds.length == _resources.length, "input error"); - uint length = _tokenIds.length; - - for (uint i = 0; i < length; i++) { - startMining(_tokenIds[i], _landTokenIds[i], _resources[i]); - } - - } - - // Only trigger from Token Activity. - function activityStopped(uint256 _tokenId) public auth { - - _stopMining(_tokenId); - } - - function stopMining(uint256 _tokenId) public { - ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).removeActivity(_tokenId, msg.sender); - } - - function _stopMining(uint256 _tokenId) internal { - // remove the miner from land2ResourceMineState; - uint64 minerIndex = miner2Index[_tokenId].indexInResource; - address resource = miner2Index[_tokenId].resource; - uint256 landTokenId = miner2Index[_tokenId].landTokenId; - - // update status! - mine(landTokenId); - - uint64 lastMinerIndex = uint64(land2ResourceMineState[landTokenId].miners[resource].length.sub(1)); - uint256 lastMiner = land2ResourceMineState[landTokenId].miners[resource][lastMinerIndex]; - - land2ResourceMineState[landTokenId].miners[resource][minerIndex] = lastMiner; - land2ResourceMineState[landTokenId].miners[resource][lastMinerIndex] = 0; - - land2ResourceMineState[landTokenId].miners[resource].length -= 1; - miner2Index[lastMiner].indexInResource = minerIndex; - - land2ResourceMineState[landTokenId].totalMiners -= 1; - - address miner = IInterstellarEncoder(registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER)).getObjectAddress(_tokenId); - uint256 strength = IMinerObject(miner).strengthOf(_tokenId, resource, landTokenId); - - // for backward compatibility - // if strength can fluctuate some time in the future - if (land2ResourceMineState[landTokenId].totalMinerStrength[resource] != 0) { - if (land2ResourceMineState[landTokenId].totalMinerStrength[resource] > strength) { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] = land2ResourceMineState[landTokenId].totalMinerStrength[resource].sub(strength); - } else { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] = 0; - } - } - - if (land2ResourceMineState[landTokenId].totalMiners == 0) { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] = 0; - } - - delete miner2Index[_tokenId]; - - emit StopMining(_tokenId, landTokenId, resource, strength); - } - - function getMinerOnLand(uint _landTokenId, address _resourceToken, uint _index) public view returns (uint256) { - return land2ResourceMineState[_landTokenId].miners[_resourceToken][_index]; - } - - function getTotalMiningStrength(uint _landTokenId, address _resourceToken) public view returns (uint256) { - return land2ResourceMineState[_landTokenId].totalMinerStrength[_resourceToken]; - } - - function availableResources(uint256 _landTokenId, address[5] _resourceTokens) public view returns (uint256, uint256, uint256, uint256, uint256) { - - uint availableGold = _calculateMinedBalance(_landTokenId, _resourceTokens[0], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[0]]; - uint availableWood = _calculateMinedBalance(_landTokenId, _resourceTokens[1], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[1]]; - uint availableWater = _calculateMinedBalance(_landTokenId, _resourceTokens[2], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[2]]; - uint availableFire = _calculateMinedBalance(_landTokenId, _resourceTokens[3], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[3]]; - uint availableSoil = _calculateMinedBalance(_landTokenId, _resourceTokens[4], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[4]]; - - return (availableGold, availableWood, availableWater, availableFire, availableSoil); - } - - function mintedBalanceOnLand(uint256 _landTokenId, address _resourceToken) public view returns (uint256) { - return land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken]; - } - - function landWorkingOn(uint256 _apostleTokenId) public view returns (uint256 landTokenId) { - landTokenId = miner2Index[_apostleTokenId].landTokenId; - } - - - - - function _updateMinerStrength(uint256 _apostleTokenId, bool _isStop) internal returns (uint256, uint256){ - // require that this apostle - uint256 landTokenId = landWorkingOn(_apostleTokenId); - require(landTokenId != 0, "this apostle is not mining."); - - address resource = miner2Index[_apostleTokenId].resource; - - address miner = IInterstellarEncoder(registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER)).getObjectAddress(_apostleTokenId); - uint256 strength = IMinerObject(miner).strengthOf(_apostleTokenId, resource, landTokenId); - - mine(landTokenId); - - if (_isStop) { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] = land2ResourceMineState[landTokenId].totalMinerStrength[resource].sub(strength); - } else { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] += strength; - } - - return (landTokenId, strength); - } - - // when a mirrorToken or a pet has tied to apostle - // we need to update status and remove this apostle from mining list first - // open authority to PetBase - // can only be called by PetBase - function updateMinerStrengthWhenStop(uint256 _apostleTokenId) public auth { - uint256 landTokenId; - uint256 strength; - (landTokenId, strength) = _updateMinerStrength(_apostleTokenId, true); - // _isStop == true - minus strength - // _isStop == false - add strength - emit UpdateMiningStrengthWhenStop(_apostleTokenId, landTokenId, strength); - } - - function updateMinerStrengthWhenStart(uint256 _apostleTokenId) public auth { - uint256 landTokenId; - uint256 strength; - (landTokenId, strength) = _updateMinerStrength(_apostleTokenId, false); - // _isStop == true - minus strength - // _isStop == false - add strength - emit UpdateMiningStrengthWhenStart(_apostleTokenId, landTokenId, strength); - } - -} \ No newline at end of file diff --git a/flat/LandResourceV4.sol b/flat/LandResourceV4.sol deleted file mode 100644 index c4395f3..0000000 --- a/flat/LandResourceV4.sol +++ /dev/null @@ -1,1068 +0,0 @@ -// Dependency file: openzeppelin-solidity/contracts/math/SafeMath.sol - -// pragma solidity ^0.4.24; - - -/** - * @title SafeMath - * @dev Math operations with safety checks that throw on error - */ -library SafeMath { - - /** - * @dev Multiplies two numbers, throws on overflow. - */ - function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) { - // Gas optimization: this is cheaper than asserting 'a' not being zero, but the - // benefit is lost if 'b' is also tested. - // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 - if (_a == 0) { - return 0; - } - - c = _a * _b; - assert(c / _a == _b); - return c; - } - - /** - * @dev Integer division of two numbers, truncating the quotient. - */ - function div(uint256 _a, uint256 _b) internal pure returns (uint256) { - // assert(_b > 0); // Solidity automatically throws when dividing by 0 - // uint256 c = _a / _b; - // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold - return _a / _b; - } - - /** - * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). - */ - function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { - assert(_b <= _a); - return _a - _b; - } - - /** - * @dev Adds two numbers, throws on overflow. - */ - function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) { - c = _a + _b; - assert(c >= _a); - return c; - } -} - - -// Dependency file: openzeppelin-solidity/contracts/introspection/ERC165.sol - -// pragma solidity ^0.4.24; - - -/** - * @title ERC165 - * @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md - */ -interface ERC165 { - - /** - * @notice Query if a contract implements an interface - * @param _interfaceId The interface identifier, as specified in ERC-165 - * @dev Interface identification is specified in ERC-165. This function - * uses less than 30,000 gas. - */ - function supportsInterface(bytes4 _interfaceId) - external - view - returns (bool); -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - - -/** - * @title ERC721 Non-Fungible Token Standard basic interface - * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Basic is ERC165 { - - bytes4 internal constant InterfaceId_ERC721 = 0x80ac58cd; - /* - * 0x80ac58cd === - * bytes4(keccak256('balanceOf(address)')) ^ - * bytes4(keccak256('ownerOf(uint256)')) ^ - * bytes4(keccak256('approve(address,uint256)')) ^ - * bytes4(keccak256('getApproved(uint256)')) ^ - * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ - * bytes4(keccak256('isApprovedForAll(address,address)')) ^ - * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ - * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ - * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) - */ - - bytes4 internal constant InterfaceId_ERC721Exists = 0x4f558e79; - /* - * 0x4f558e79 === - * bytes4(keccak256('exists(uint256)')) - */ - - bytes4 internal constant InterfaceId_ERC721Enumerable = 0x780e9d63; - /** - * 0x780e9d63 === - * bytes4(keccak256('totalSupply()')) ^ - * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) ^ - * bytes4(keccak256('tokenByIndex(uint256)')) - */ - - bytes4 internal constant InterfaceId_ERC721Metadata = 0x5b5e139f; - /** - * 0x5b5e139f === - * bytes4(keccak256('name()')) ^ - * bytes4(keccak256('symbol()')) ^ - * bytes4(keccak256('tokenURI(uint256)')) - */ - - event Transfer( - address indexed _from, - address indexed _to, - uint256 indexed _tokenId - ); - event Approval( - address indexed _owner, - address indexed _approved, - uint256 indexed _tokenId - ); - event ApprovalForAll( - address indexed _owner, - address indexed _operator, - bool _approved - ); - - function balanceOf(address _owner) public view returns (uint256 _balance); - function ownerOf(uint256 _tokenId) public view returns (address _owner); - function exists(uint256 _tokenId) public view returns (bool _exists); - - function approve(address _to, uint256 _tokenId) public; - function getApproved(uint256 _tokenId) - public view returns (address _operator); - - function setApprovalForAll(address _operator, bool _approved) public; - function isApprovedForAll(address _owner, address _operator) - public view returns (bool); - - function transferFrom(address _from, address _to, uint256 _tokenId) public; - function safeTransferFrom(address _from, address _to, uint256 _tokenId) - public; - - function safeTransferFrom( - address _from, - address _to, - uint256 _tokenId, - bytes _data - ) - public; -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol"; - - -/** - * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Enumerable is ERC721Basic { - function totalSupply() public view returns (uint256); - function tokenOfOwnerByIndex( - address _owner, - uint256 _index - ) - public - view - returns (uint256 _tokenId); - - function tokenByIndex(uint256 _index) public view returns (uint256); -} - - -/** - * @title ERC-721 Non-Fungible Token Standard, optional metadata extension - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Metadata is ERC721Basic { - function name() external view returns (string _name); - function symbol() external view returns (string _symbol); - function tokenURI(uint256 _tokenId) public view returns (string); -} - - -/** - * @title ERC-721 Non-Fungible Token Standard, full implementation interface - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721 is ERC721Basic, ERC721Enumerable, ERC721Metadata { -} - - -// Dependency file: openzeppelin-solidity/contracts/introspection/SupportsInterfaceWithLookup.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - - -/** - * @title SupportsInterfaceWithLookup - * @author Matt Condon (@shrugs) - * @dev Implements ERC165 using a lookup table. - */ -contract SupportsInterfaceWithLookup is ERC165 { - - bytes4 public constant InterfaceId_ERC165 = 0x01ffc9a7; - /** - * 0x01ffc9a7 === - * bytes4(keccak256('supportsInterface(bytes4)')) - */ - - /** - * @dev a mapping of interface id to whether or not it's supported - */ - mapping(bytes4 => bool) internal supportedInterfaces; - - /** - * @dev A contract implementing SupportsInterfaceWithLookup - * implement ERC165 itself - */ - constructor() - public - { - _registerInterface(InterfaceId_ERC165); - } - - /** - * @dev implement supportsInterface(bytes4) using a lookup table - */ - function supportsInterface(bytes4 _interfaceId) - external - view - returns (bool) - { - return supportedInterfaces[_interfaceId]; - } - - /** - * @dev private method for registering an interface - */ - function _registerInterface(bytes4 _interfaceId) - internal - { - require(_interfaceId != 0xffffffff); - supportedInterfaces[_interfaceId] = true; - } -} - - -// Dependency file: @evolutionland/common/contracts/interfaces/IMintableERC20.sol - -// pragma solidity ^0.4.23; - -contract IMintableERC20 { - - function mint(address _to, uint256 _value) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/ISettingsRegistry.sol - -// pragma solidity ^0.4.24; - -contract ISettingsRegistry { - enum SettingsValueTypes { NONE, UINT, STRING, ADDRESS, BYTES, BOOL, INT } - - function uintOf(bytes32 _propertyName) public view returns (uint256); - - function stringOf(bytes32 _propertyName) public view returns (string); - - function addressOf(bytes32 _propertyName) public view returns (address); - - function bytesOf(bytes32 _propertyName) public view returns (bytes); - - function boolOf(bytes32 _propertyName) public view returns (bool); - - function intOf(bytes32 _propertyName) public view returns (int); - - function setUintProperty(bytes32 _propertyName, uint _value) public; - - function setStringProperty(bytes32 _propertyName, string _value) public; - - function setAddressProperty(bytes32 _propertyName, address _value) public; - - function setBytesProperty(bytes32 _propertyName, bytes _value) public; - - function setBoolProperty(bytes32 _propertyName, bool _value) public; - - function setIntProperty(bytes32 _propertyName, int _value) public; - - function getValueTypeOf(bytes32 _propertyName) public view returns (uint /* SettingsValueTypes */ ); - - event ChangeProperty(bytes32 indexed _propertyName, uint256 _type); -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IAuthority.sol - -// pragma solidity ^0.4.24; - -contract IAuthority { - function canCall( - address src, address dst, bytes4 sig - ) public view returns (bool); -} - -// Dependency file: @evolutionland/common/contracts/DSAuth.sol - -// pragma solidity ^0.4.24; - -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/IAuthority.sol'; - -contract DSAuthEvents { - event LogSetAuthority (address indexed authority); - event LogSetOwner (address indexed owner); -} - -/** - * @title DSAuth - * @dev The DSAuth contract is reference implement of https://github.com/dapphub/ds-auth - * But in the isAuthorized method, the src from address(this) is remove for safty concern. - */ -contract DSAuth is DSAuthEvents { - IAuthority public authority; - address public owner; - - constructor() public { - owner = msg.sender; - emit LogSetOwner(msg.sender); - } - - function setOwner(address owner_) - public - auth - { - owner = owner_; - emit LogSetOwner(owner); - } - - function setAuthority(IAuthority authority_) - public - auth - { - authority = authority_; - emit LogSetAuthority(authority); - } - - modifier auth { - require(isAuthorized(msg.sender, msg.sig)); - _; - } - - modifier onlyOwner() { - require(msg.sender == owner); - _; - } - - function isAuthorized(address src, bytes4 sig) internal view returns (bool) { - if (src == owner) { - return true; - } else if (authority == IAuthority(0)) { - return false; - } else { - return authority.canCall(src, this, sig); - } - } -} - - -// Dependency file: @evolutionland/common/contracts/SettingIds.sol - -// pragma solidity ^0.4.24; - -/** - Id definitions for SettingsRegistry.sol - Can be used in conjunction with the settings registry to get properties -*/ -contract SettingIds { - bytes32 public constant CONTRACT_RING_ERC20_TOKEN = "CONTRACT_RING_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_KTON_ERC20_TOKEN = "CONTRACT_KTON_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_GOLD_ERC20_TOKEN = "CONTRACT_GOLD_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_WOOD_ERC20_TOKEN = "CONTRACT_WOOD_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_WATER_ERC20_TOKEN = "CONTRACT_WATER_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_FIRE_ERC20_TOKEN = "CONTRACT_FIRE_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_SOIL_ERC20_TOKEN = "CONTRACT_SOIL_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_OBJECT_OWNERSHIP = "CONTRACT_OBJECT_OWNERSHIP"; - - bytes32 public constant CONTRACT_TOKEN_LOCATION = "CONTRACT_TOKEN_LOCATION"; - - bytes32 public constant CONTRACT_LAND_BASE = "CONTRACT_LAND_BASE"; - - bytes32 public constant CONTRACT_USER_POINTS = "CONTRACT_USER_POINTS"; - - bytes32 public constant CONTRACT_INTERSTELLAR_ENCODER = "CONTRACT_INTERSTELLAR_ENCODER"; - - bytes32 public constant CONTRACT_DIVIDENDS_POOL = "CONTRACT_DIVIDENDS_POOL"; - - bytes32 public constant CONTRACT_TOKEN_USE = "CONTRACT_TOKEN_USE"; - - bytes32 public constant CONTRACT_REVENUE_POOL = "CONTRACT_REVENUE_POOL"; - - bytes32 public constant CONTRACT_ERC721_BRIDGE = "CONTRACT_ERC721_BRIDGE"; - - bytes32 public constant CONTRACT_PET_BASE = "CONTRACT_PET_BASE"; - - // Cut owner takes on each auction, measured in basis points (1/100 of a percent). - // this can be considered as transaction fee. - // Values 0-10,000 map to 0%-100% - // set ownerCut to 4% - // ownerCut = 400; - bytes32 public constant UINT_AUCTION_CUT = "UINT_AUCTION_CUT"; // Denominator is 10000 - - bytes32 public constant UINT_TOKEN_OFFER_CUT = "UINT_TOKEN_OFFER_CUT"; // Denominator is 10000 - - // Cut referer takes on each auction, measured in basis points (1/100 of a percent). - // which cut from transaction fee. - // Values 0-10,000 map to 0%-100% - // set refererCut to 4% - // refererCut = 400; - bytes32 public constant UINT_REFERER_CUT = "UINT_REFERER_CUT"; - - bytes32 public constant CONTRACT_LAND_RESOURCE = "CONTRACT_LAND_RESOURCE"; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IInterstellarEncoder.sol - -// pragma solidity ^0.4.24; - -contract IInterstellarEncoder { - uint256 constant CLEAR_HIGH = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff; - - uint256 public constant MAGIC_NUMBER = 42; // Interstellar Encoding Magic Number. - uint256 public constant CHAIN_ID = 1; // Ethereum mainet. - uint256 public constant CURRENT_LAND = 1; // 1 is Atlantis, 0 is NaN. - - enum ObjectClass { - NaN, - LAND, - APOSTLE, - OBJECT_CLASS_COUNT - } - - function registerNewObjectClass(address _objectContract, uint8 objectClass) public; - - function registerNewTokenContract(address _tokenAddress) public; - - function encodeTokenId(address _tokenAddress, uint8 _objectClass, uint128 _objectIndex) public view returns (uint256 _tokenId); - - function encodeTokenIdForObjectContract( - address _tokenAddress, address _objectContract, uint128 _objectId) public view returns (uint256 _tokenId); - - function getContractAddress(uint256 _tokenId) public view returns (address); - - function getObjectId(uint256 _tokenId) public view returns (uint128 _objectId); - - function getObjectClass(uint256 _tokenId) public view returns (uint8); - - function getObjectAddress(uint256 _tokenId) public view returns (address); -} - -// Dependency file: @evolutionland/common/contracts/interfaces/ITokenUse.sol - -// pragma solidity ^0.4.24; - -contract ITokenUse { - uint48 public constant MAX_UINT48_TIME = 281474976710655; - - function isObjectInHireStage(uint256 _tokenId) public view returns (bool); - - function isObjectReadyToUse(uint256 _tokenId) public view returns (bool); - - function getTokenUser(uint256 _tokenId) public view returns (address); - - function createTokenUseOffer(uint256 _tokenId, uint256 _duration, uint256 _price, address _acceptedActivity) public; - - function cancelTokenUseOffer(uint256 _tokenId) public; - - function takeTokenUseOffer(uint256 _tokenId) public; - - function addActivity(uint256 _tokenId, address _user, uint256 _endTime) public; - - function removeActivity(uint256 _tokenId, address _user) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IActivity.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - -contract IActivity is ERC165 { - bytes4 internal constant InterfaceId_IActivity = 0x6086e7f8; - /* - * 0x6086e7f8 === - * bytes4(keccak256('activityStopped(uint256)')) - */ - - function activityStopped(uint256 _tokenId) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IMinerObject.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - -contract IMinerObject is ERC165 { - bytes4 internal constant InterfaceId_IMinerObject = 0x64272b75; - - /* - * 0x64272b752 === - * bytes4(keccak256('strengthOf(uint256,address)')) - */ - - function strengthOf(uint256 _tokenId, address _resourceToken, uint256 _landTokenId) public view returns (uint256); - -} - -// Dependency file: contracts/interfaces/ILandBase.sol - -// pragma solidity ^0.4.24; - -contract ILandBase { - - /* - * Event - */ - event ModifiedResourceRate(uint indexed tokenId, address resourceToken, uint16 newResourceRate); - event HasboxSetted(uint indexed tokenId, bool hasBox); - - event ChangedReourceRateAttr(uint indexed tokenId, uint256 attr); - - event ChangedFlagMask(uint indexed tokenId, uint256 newFlagMask); - - event CreatedNewLand(uint indexed tokenId, int x, int y, address beneficiary, uint256 resourceRateAttr, uint256 mask); - - function defineResouceTokenRateAttrId(address _resourceToken, uint8 _attrId) public; - - function setHasBox(uint _landTokenID, bool isHasBox) public; - function isReserved(uint256 _tokenId) public view returns (bool); - function isSpecial(uint256 _tokenId) public view returns (bool); - function isHasBox(uint256 _tokenId) public view returns (bool); - - function getResourceRateAttr(uint _landTokenId) public view returns (uint256); - function setResourceRateAttr(uint _landTokenId, uint256 _newResourceRateAttr) public; - - function getResourceRate(uint _landTokenId, address _resouceToken) public view returns (uint16); - function setResourceRate(uint _landTokenID, address _resourceToken, uint16 _newResouceRate) public; - - function getFlagMask(uint _landTokenId) public view returns (uint256); - - function setFlagMask(uint _landTokenId, uint256 _newFlagMask) public; - - function resourceToken2RateAttrId(address _resourceToken) external view returns (uint256); -} - - -// Dependency file: contracts/LandSettingIds.sol - -// pragma solidity ^0.4.24; - -// import "@evolutionland/common/contracts/SettingIds.sol"; - -contract LandSettingIds is SettingIds { - -} - -// Root file: contracts/LandResourceV4.sol - -pragma solidity ^0.4.23; - -// import "openzeppelin-solidity/contracts/math/SafeMath.sol"; -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; -// import "openzeppelin-solidity/contracts/introspection/SupportsInterfaceWithLookup.sol"; -// import "@evolutionland/common/contracts/interfaces/IMintableERC20.sol"; -// import "@evolutionland/common/contracts/interfaces/ISettingsRegistry.sol"; -// import "@evolutionland/common/contracts/DSAuth.sol"; -// import "@evolutionland/common/contracts/SettingIds.sol"; -// import "@evolutionland/common/contracts/interfaces/IInterstellarEncoder.sol"; -// import "@evolutionland/common/contracts/interfaces/ITokenUse.sol"; -// import "@evolutionland/common/contracts/interfaces/IActivity.sol"; -// import "@evolutionland/common/contracts/interfaces/IMinerObject.sol"; -// import "contracts/interfaces/ILandBase.sol"; -// import "contracts/LandSettingIds.sol"; - -/** - * @title LandResource - * @dev LandResource is registry that manage the element resources generated on Land, and related resource releasing speed. - * difference between LandResourceV2: - 1. add function landWorkingOn to get which land the apostle is working on - 2. add function updateMinerStrength to update miner strength on land - 3. add event UpdateMiningStrength - */ - - -contract LandResourceV4 is SupportsInterfaceWithLookup, DSAuth, IActivity, LandSettingIds { - using SafeMath for *; - - // For every seconds, the speed will decrease by current speed multiplying (DENOMINATOR_in_seconds - seconds) / DENOMINATOR_in_seconds - // resource will decrease 1/10000 every day. - uint256 public constant DENOMINATOR = 10000; - - uint256 public constant TOTAL_SECONDS = DENOMINATOR * (1 days); - - bool private singletonLock = false; - - ISettingsRegistry public registry; - - uint256 public resourceReleaseStartTime; - - // TODO: move to global settings contract. - uint256 public attenPerDay = 1; - uint256 public recoverAttenPerDay = 20; - - // Struct for recording resouces on land which have already been pinged. - // 金, Evolution Land Gold - // 木, Evolution Land Wood - // 水, Evolution Land Water - // 火, Evolution Land fire - // 土, Evolution Land Silicon - struct ResourceMineState { - mapping(address => uint256) mintedBalance; - mapping(address => uint256[]) miners; - mapping(address => uint256) totalMinerStrength; - uint256 lastUpdateSpeedInSeconds; - uint256 lastDestoryAttenInSeconds; - uint256 industryIndex; - uint128 lastUpdateTime; - uint64 totalMiners; - uint64 maxMiners; - } - - struct MinerStatus { - uint256 landTokenId; - address resource; - uint64 indexInResource; - } - - mapping(uint256 => ResourceMineState) public land2ResourceMineState; - - mapping(uint256 => MinerStatus) public miner2Index; - - /* - * Event - */ - - event StartMining(uint256 minerTokenId, uint256 landTokenId, address _resource, uint256 strength); - event StopMining(uint256 minerTokenId, uint256 landTokenId, address _resource, uint256 strength); - event ResourceClaimed(address owner, uint256 landTokenId, uint256 goldBalance, uint256 woodBalance, uint256 waterBalance, uint256 fireBalance, uint256 soilBalance); - - event UpdateMiningStrengthWhenStop(uint256 apostleTokenId, uint256 landTokenId, uint256 strength); - event UpdateMiningStrengthWhenStart(uint256 apostleTokenId, uint256 landTokenId, uint256 strength); - /* - * Modifiers - */ - modifier singletonLockCall() { - require(!singletonLock, "Only can call once"); - _; - singletonLock = true; - } - - - function initializeContract(address _registry, uint256 _resourceReleaseStartTime) public singletonLockCall { - // Ownable constructor - owner = msg.sender; - emit LogSetOwner(msg.sender); - - registry = ISettingsRegistry(_registry); - - resourceReleaseStartTime = _resourceReleaseStartTime; - - _registerInterface(InterfaceId_IActivity); - } - - // get amount of speed uint at this moment - function _getReleaseSpeedInSeconds(uint256 _tokenId, uint256 _time) internal view returns (uint256 currentSpeed) { - require(_time >= resourceReleaseStartTime, "Should after release time"); - require(_time >= land2ResourceMineState[_tokenId].lastUpdateTime, "Should after release last update time"); - - // after 10000 days from start - // the resource release speed decreases to 0 - if (TOTAL_SECONDS < _time - resourceReleaseStartTime) - { - return 0; - } - - // max amount of speed unit of _tokenId for now - // suppose that speed_uint = 1 in this function - uint256 availableSpeedInSeconds = TOTAL_SECONDS.sub(_time - resourceReleaseStartTime); - // time from last update - uint256 timeBetween = _time - land2ResourceMineState[_tokenId].lastUpdateTime; - - // the recover speed is 20/10000, 20 times. - // recoveryRate overall from lasUpdateTime til now + amount of speed uint at lastUpdateTime - uint256 nextSpeedInSeconds = land2ResourceMineState[_tokenId].lastUpdateSpeedInSeconds + timeBetween * recoverAttenPerDay; - // destroyRate overall from lasUpdateTime til now amount of speed uint at lastUpdateTime - uint256 destroyedSpeedInSeconds = timeBetween * land2ResourceMineState[_tokenId].lastDestoryAttenInSeconds; - - if (nextSpeedInSeconds < destroyedSpeedInSeconds) - { - nextSpeedInSeconds = 0; - } else { - nextSpeedInSeconds = nextSpeedInSeconds - destroyedSpeedInSeconds; - } - - if (nextSpeedInSeconds > availableSpeedInSeconds) { - nextSpeedInSeconds = availableSpeedInSeconds; - } - - return nextSpeedInSeconds; - } - - function getReleaseSpeed(uint256 _tokenId, address _resourceToken, uint256 _time) public view returns (uint256 currentSpeed) { - return ILandBase(registry.addressOf(CONTRACT_LAND_BASE)) - .getResourceRate(_tokenId, _resourceToken).mul(_getReleaseSpeedInSeconds(_tokenId, _time)) - .div(TOTAL_SECONDS); - } - - /** - * @dev Get and Query the amount of resources available from lastUpdateTime to now for use on specific land. - * @param _tokenId The token id of specific land. - */ - function _getMinableBalance(uint256 _tokenId, address _resourceToken, uint256 _currentTime, uint256 _lastUpdateTime) public view returns (uint256 minableBalance) { - - uint256 speed_in_current_period = ILandBase(registry.addressOf(CONTRACT_LAND_BASE)) - .getResourceRate(_tokenId, _resourceToken).mul(_getReleaseSpeedInSeconds(_tokenId, ((_currentTime + _lastUpdateTime) / 2))).mul(1 ether).div(1 days).div(TOTAL_SECONDS); - - // calculate the area of trapezoid - minableBalance = speed_in_current_period.mul(_currentTime - _lastUpdateTime); - } - - function _getMaxMineBalance(uint256 _tokenId, address _resourceToken, uint256 _currentTime, uint256 _lastUpdateTime) internal view returns (uint256) { - // totalMinerStrength is in wei - uint256 mineSpeed = land2ResourceMineState[_tokenId].totalMinerStrength[_resourceToken]; - - return mineSpeed.mul(_currentTime - _lastUpdateTime).div(1 days); - } - - function mine(uint256 _landTokenId) public { - _mineAllResource( - _landTokenId, - registry.addressOf(CONTRACT_GOLD_ERC20_TOKEN), - registry.addressOf(CONTRACT_WOOD_ERC20_TOKEN), - registry.addressOf(CONTRACT_WATER_ERC20_TOKEN), - registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN), - registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN) - ); - } - - function _mineAllResource(uint256 _landTokenId, address _gold, address _wood, address _water, address _fire, address _soil) internal { - require(IInterstellarEncoder(registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER)).getObjectClass(_landTokenId) == 1, "Token must be land."); - - if (land2ResourceMineState[_landTokenId].lastUpdateTime == 0) { - land2ResourceMineState[_landTokenId].lastUpdateTime = uint128(resourceReleaseStartTime); - land2ResourceMineState[_landTokenId].lastUpdateSpeedInSeconds = TOTAL_SECONDS; - } - - _mineResource(_landTokenId, _gold); - _mineResource(_landTokenId, _wood); - _mineResource(_landTokenId, _water); - _mineResource(_landTokenId, _fire); - _mineResource(_landTokenId, _soil); - - land2ResourceMineState[_landTokenId].lastUpdateSpeedInSeconds = _getReleaseSpeedInSeconds(_landTokenId, now); - land2ResourceMineState[_landTokenId].lastUpdateTime = uint128(now); - - } - - function _mineResource(uint256 _landTokenId, address _resourceToken) internal { - // the longest seconds to zero speed. - uint minedBalance = _calculateMinedBalance(_landTokenId, _resourceToken, now); - - land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken] += minedBalance; - } - - function _calculateMinedBalance(uint256 _landTokenId, address _resourceToken, uint256 _currentTime) internal returns (uint256) { - uint256 currentTime = _currentTime; - - uint256 minedBalance; - uint256 minableBalance; - if (currentTime > (resourceReleaseStartTime + TOTAL_SECONDS)) - { - currentTime = (resourceReleaseStartTime + TOTAL_SECONDS); - } - - uint256 lastUpdateTime = land2ResourceMineState[_landTokenId].lastUpdateTime; - require(currentTime >= lastUpdateTime); - - if (lastUpdateTime >= (resourceReleaseStartTime + TOTAL_SECONDS)) { - minedBalance = 0; - minableBalance = 0; - } else { - minedBalance = _getMaxMineBalance(_landTokenId, _resourceToken, currentTime, lastUpdateTime); - minableBalance = _getMinableBalance(_landTokenId, _resourceToken, currentTime, lastUpdateTime); - } - - - if (minedBalance > minableBalance) { - minedBalance = minableBalance; - } - - return minedBalance; - } - - function claimAllResource(uint256 _landTokenId) public { - require(msg.sender == ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(_landTokenId), "Must be the owner of the land"); - - address gold = registry.addressOf(CONTRACT_GOLD_ERC20_TOKEN); - address wood = registry.addressOf(CONTRACT_WOOD_ERC20_TOKEN); - address water = registry.addressOf(CONTRACT_WATER_ERC20_TOKEN); - address fire = registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN); - address soil = registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN); - - _mineAllResource(_landTokenId, gold, wood, water, fire, soil); - - uint goldBalance; - uint woodBalance; - uint waterBalance; - uint fireBalance; - uint soilBalance; - - if (land2ResourceMineState[_landTokenId].mintedBalance[gold] > 0) { - goldBalance = land2ResourceMineState[_landTokenId].mintedBalance[gold]; - IMintableERC20(gold).mint(msg.sender, goldBalance); - land2ResourceMineState[_landTokenId].mintedBalance[gold] = 0; - } - - if (land2ResourceMineState[_landTokenId].mintedBalance[wood] > 0) { - woodBalance = land2ResourceMineState[_landTokenId].mintedBalance[wood]; - IMintableERC20(wood).mint(msg.sender, woodBalance); - land2ResourceMineState[_landTokenId].mintedBalance[wood] = 0; - } - - if (land2ResourceMineState[_landTokenId].mintedBalance[water] > 0) { - waterBalance = land2ResourceMineState[_landTokenId].mintedBalance[water]; - IMintableERC20(water).mint(msg.sender, waterBalance); - land2ResourceMineState[_landTokenId].mintedBalance[water] = 0; - } - - if (land2ResourceMineState[_landTokenId].mintedBalance[fire] > 0) { - fireBalance = land2ResourceMineState[_landTokenId].mintedBalance[fire]; - IMintableERC20(fire).mint(msg.sender, fireBalance); - land2ResourceMineState[_landTokenId].mintedBalance[fire] = 0; - } - - if (land2ResourceMineState[_landTokenId].mintedBalance[soil] > 0) { - soilBalance = land2ResourceMineState[_landTokenId].mintedBalance[soil]; - IMintableERC20(soil).mint(msg.sender, soilBalance); - land2ResourceMineState[_landTokenId].mintedBalance[soil] = 0; - } - - emit ResourceClaimed(msg.sender, _landTokenId, goldBalance, woodBalance, waterBalance, fireBalance, soilBalance); - } - - // both for own _tokenId or hired one - function startMining(uint256 _tokenId, uint256 _landTokenId, address _resource) public { - ITokenUse tokenUse = ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)); - - tokenUse.addActivity(_tokenId, msg.sender, 0); - - // require the permission from land owner; - require(msg.sender == ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(_landTokenId), "Must be the owner of the land"); - - // make sure that _tokenId won't be used repeatedly - require(miner2Index[_tokenId].landTokenId == 0); - - // update status! - mine(_landTokenId); - - uint256 _index = land2ResourceMineState[_landTokenId].miners[_resource].length; - - land2ResourceMineState[_landTokenId].totalMiners += 1; - - if (land2ResourceMineState[_landTokenId].maxMiners == 0) { - land2ResourceMineState[_landTokenId].maxMiners = 5; - } - - require(land2ResourceMineState[_landTokenId].totalMiners <= land2ResourceMineState[_landTokenId].maxMiners); - - address miner = IInterstellarEncoder(registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER)).getObjectAddress(_tokenId); - uint256 strength = IMinerObject(miner).strengthOf(_tokenId, _resource, _landTokenId); - - land2ResourceMineState[_landTokenId].miners[_resource].push(_tokenId); - land2ResourceMineState[_landTokenId].totalMinerStrength[_resource] += strength; - - miner2Index[_tokenId] = MinerStatus({ - landTokenId : _landTokenId, - resource : _resource, - indexInResource : uint64(_index) - }); - - emit StartMining(_tokenId, _landTokenId, _resource, strength); - - } - - function batchStartMining(uint256[] _tokenIds, uint256[] _landTokenIds, address[] _resources) public { - require(_tokenIds.length == _landTokenIds.length && _landTokenIds.length == _resources.length, "input error"); - uint length = _tokenIds.length; - - for (uint i = 0; i < length; i++) { - startMining(_tokenIds[i], _landTokenIds[i], _resources[i]); - } - - } - - function batchClaimAllResource(uint256[] _landTokenIds) public { - uint length = _landTokenIds.length; - - for (uint i = 0; i < length; i++) { - claimAllResource(_landTokenIds[i]); - } - } - - // Only trigger from Token Activity. - function activityStopped(uint256 _tokenId) public auth { - - _stopMining(_tokenId); - } - - function stopMining(uint256 _tokenId) public { - ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).removeActivity(_tokenId, msg.sender); - } - - function _stopMining(uint256 _tokenId) internal { - // remove the miner from land2ResourceMineState; - uint64 minerIndex = miner2Index[_tokenId].indexInResource; - address resource = miner2Index[_tokenId].resource; - uint256 landTokenId = miner2Index[_tokenId].landTokenId; - - // update status! - mine(landTokenId); - - uint64 lastMinerIndex = uint64(land2ResourceMineState[landTokenId].miners[resource].length.sub(1)); - uint256 lastMiner = land2ResourceMineState[landTokenId].miners[resource][lastMinerIndex]; - - land2ResourceMineState[landTokenId].miners[resource][minerIndex] = lastMiner; - land2ResourceMineState[landTokenId].miners[resource][lastMinerIndex] = 0; - - land2ResourceMineState[landTokenId].miners[resource].length -= 1; - miner2Index[lastMiner].indexInResource = minerIndex; - - land2ResourceMineState[landTokenId].totalMiners -= 1; - - address miner = IInterstellarEncoder(registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER)).getObjectAddress(_tokenId); - uint256 strength = IMinerObject(miner).strengthOf(_tokenId, resource, landTokenId); - - // for backward compatibility - // if strength can fluctuate some time in the future - if (land2ResourceMineState[landTokenId].totalMinerStrength[resource] != 0) { - if (land2ResourceMineState[landTokenId].totalMinerStrength[resource] > strength) { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] = land2ResourceMineState[landTokenId].totalMinerStrength[resource].sub(strength); - } else { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] = 0; - } - } - - if (land2ResourceMineState[landTokenId].totalMiners == 0) { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] = 0; - } - - delete miner2Index[_tokenId]; - - emit StopMining(_tokenId, landTokenId, resource, strength); - } - - function getMinerOnLand(uint _landTokenId, address _resourceToken, uint _index) public view returns (uint256) { - return land2ResourceMineState[_landTokenId].miners[_resourceToken][_index]; - } - - function getTotalMiningStrength(uint _landTokenId, address _resourceToken) public view returns (uint256) { - return land2ResourceMineState[_landTokenId].totalMinerStrength[_resourceToken]; - } - - function availableResources(uint256 _landTokenId, address[5] _resourceTokens) public view returns (uint256, uint256, uint256, uint256, uint256) { - - uint availableGold = _calculateMinedBalance(_landTokenId, _resourceTokens[0], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[0]]; - uint availableWood = _calculateMinedBalance(_landTokenId, _resourceTokens[1], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[1]]; - uint availableWater = _calculateMinedBalance(_landTokenId, _resourceTokens[2], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[2]]; - uint availableFire = _calculateMinedBalance(_landTokenId, _resourceTokens[3], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[3]]; - uint availableSoil = _calculateMinedBalance(_landTokenId, _resourceTokens[4], now) + land2ResourceMineState[_landTokenId].mintedBalance[_resourceTokens[4]]; - - return (availableGold, availableWood, availableWater, availableFire, availableSoil); - } - - function mintedBalanceOnLand(uint256 _landTokenId, address _resourceToken) public view returns (uint256) { - return land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken]; - } - - function landWorkingOn(uint256 _apostleTokenId) public view returns (uint256 landTokenId) { - landTokenId = miner2Index[_apostleTokenId].landTokenId; - } - - - - - function _updateMinerStrength(uint256 _apostleTokenId, bool _isStop) internal returns (uint256, uint256){ - // require that this apostle - uint256 landTokenId = landWorkingOn(_apostleTokenId); - require(landTokenId != 0, "this apostle is not mining."); - - address resource = miner2Index[_apostleTokenId].resource; - - address miner = IInterstellarEncoder(registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER)).getObjectAddress(_apostleTokenId); - uint256 strength = IMinerObject(miner).strengthOf(_apostleTokenId, resource, landTokenId); - - mine(landTokenId); - - if (_isStop) { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] = land2ResourceMineState[landTokenId].totalMinerStrength[resource].sub(strength); - } else { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] += strength; - } - - return (landTokenId, strength); - } - - // when a mirrorToken or a pet has tied to apostle - // we need to update status and remove this apostle from mining list first - // open authority to PetBase - // can only be called by PetBase - function updateMinerStrengthWhenStop(uint256 _apostleTokenId) public auth { - uint256 landTokenId; - uint256 strength; - (landTokenId, strength) = _updateMinerStrength(_apostleTokenId, true); - // _isStop == true - minus strength - // _isStop == false - add strength - emit UpdateMiningStrengthWhenStop(_apostleTokenId, landTokenId, strength); - } - - function updateMinerStrengthWhenStart(uint256 _apostleTokenId) public auth { - uint256 landTokenId; - uint256 strength; - (landTokenId, strength) = _updateMinerStrength(_apostleTokenId, false); - // _isStop == true - minus strength - // _isStop == false - add strength - emit UpdateMiningStrengthWhenStart(_apostleTokenId, landTokenId, strength); - } - -} \ No newline at end of file diff --git a/flat/LandResourceV5.sol b/flat/LandResourceV5.sol deleted file mode 100644 index aa7342a..0000000 --- a/flat/LandResourceV5.sol +++ /dev/null @@ -1,1979 +0,0 @@ -// Dependency file: openzeppelin-solidity/contracts/math/SafeMath.sol - -// pragma solidity ^0.4.24; - - -/** - * @title SafeMath - * @dev Math operations with safety checks that throw on error - */ -library SafeMath { - - /** - * @dev Multiplies two numbers, throws on overflow. - */ - function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) { - // Gas optimization: this is cheaper than asserting 'a' not being zero, but the - // benefit is lost if 'b' is also tested. - // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 - if (_a == 0) { - return 0; - } - - c = _a * _b; - assert(c / _a == _b); - return c; - } - - /** - * @dev Integer division of two numbers, truncating the quotient. - */ - function div(uint256 _a, uint256 _b) internal pure returns (uint256) { - // assert(_b > 0); // Solidity automatically throws when dividing by 0 - // uint256 c = _a / _b; - // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold - return _a / _b; - } - - /** - * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). - */ - function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { - assert(_b <= _a); - return _a - _b; - } - - /** - * @dev Adds two numbers, throws on overflow. - */ - function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) { - c = _a + _b; - assert(c >= _a); - return c; - } -} - - -// Dependency file: openzeppelin-solidity/contracts/introspection/ERC165.sol - -// pragma solidity ^0.4.24; - - -/** - * @title ERC165 - * @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md - */ -interface ERC165 { - - /** - * @notice Query if a contract implements an interface - * @param _interfaceId The interface identifier, as specified in ERC-165 - * @dev Interface identification is specified in ERC-165. This function - * uses less than 30,000 gas. - */ - function supportsInterface(bytes4 _interfaceId) - external - view - returns (bool); -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - - -/** - * @title ERC721 Non-Fungible Token Standard basic interface - * @dev see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Basic is ERC165 { - - bytes4 internal constant InterfaceId_ERC721 = 0x80ac58cd; - /* - * 0x80ac58cd === - * bytes4(keccak256('balanceOf(address)')) ^ - * bytes4(keccak256('ownerOf(uint256)')) ^ - * bytes4(keccak256('approve(address,uint256)')) ^ - * bytes4(keccak256('getApproved(uint256)')) ^ - * bytes4(keccak256('setApprovalForAll(address,bool)')) ^ - * bytes4(keccak256('isApprovedForAll(address,address)')) ^ - * bytes4(keccak256('transferFrom(address,address,uint256)')) ^ - * bytes4(keccak256('safeTransferFrom(address,address,uint256)')) ^ - * bytes4(keccak256('safeTransferFrom(address,address,uint256,bytes)')) - */ - - bytes4 internal constant InterfaceId_ERC721Exists = 0x4f558e79; - /* - * 0x4f558e79 === - * bytes4(keccak256('exists(uint256)')) - */ - - bytes4 internal constant InterfaceId_ERC721Enumerable = 0x780e9d63; - /** - * 0x780e9d63 === - * bytes4(keccak256('totalSupply()')) ^ - * bytes4(keccak256('tokenOfOwnerByIndex(address,uint256)')) ^ - * bytes4(keccak256('tokenByIndex(uint256)')) - */ - - bytes4 internal constant InterfaceId_ERC721Metadata = 0x5b5e139f; - /** - * 0x5b5e139f === - * bytes4(keccak256('name()')) ^ - * bytes4(keccak256('symbol()')) ^ - * bytes4(keccak256('tokenURI(uint256)')) - */ - - event Transfer( - address indexed _from, - address indexed _to, - uint256 indexed _tokenId - ); - event Approval( - address indexed _owner, - address indexed _approved, - uint256 indexed _tokenId - ); - event ApprovalForAll( - address indexed _owner, - address indexed _operator, - bool _approved - ); - - function balanceOf(address _owner) public view returns (uint256 _balance); - function ownerOf(uint256 _tokenId) public view returns (address _owner); - function exists(uint256 _tokenId) public view returns (bool _exists); - - function approve(address _to, uint256 _tokenId) public; - function getApproved(uint256 _tokenId) - public view returns (address _operator); - - function setApprovalForAll(address _operator, bool _approved) public; - function isApprovedForAll(address _owner, address _operator) - public view returns (bool); - - function transferFrom(address _from, address _to, uint256 _tokenId) public; - function safeTransferFrom(address _from, address _to, uint256 _tokenId) - public; - - function safeTransferFrom( - address _from, - address _to, - uint256 _tokenId, - bytes _data - ) - public; -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC721/ERC721.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol"; - - -/** - * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Enumerable is ERC721Basic { - function totalSupply() public view returns (uint256); - function tokenOfOwnerByIndex( - address _owner, - uint256 _index - ) - public - view - returns (uint256 _tokenId); - - function tokenByIndex(uint256 _index) public view returns (uint256); -} - - -/** - * @title ERC-721 Non-Fungible Token Standard, optional metadata extension - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721Metadata is ERC721Basic { - function name() external view returns (string _name); - function symbol() external view returns (string _symbol); - function tokenURI(uint256 _tokenId) public view returns (string); -} - - -/** - * @title ERC-721 Non-Fungible Token Standard, full implementation interface - * @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md - */ -contract ERC721 is ERC721Basic, ERC721Enumerable, ERC721Metadata { -} - - -// Dependency file: openzeppelin-solidity/contracts/introspection/SupportsInterfaceWithLookup.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - - -/** - * @title SupportsInterfaceWithLookup - * @author Matt Condon (@shrugs) - * @dev Implements ERC165 using a lookup table. - */ -contract SupportsInterfaceWithLookup is ERC165 { - - bytes4 public constant InterfaceId_ERC165 = 0x01ffc9a7; - /** - * 0x01ffc9a7 === - * bytes4(keccak256('supportsInterface(bytes4)')) - */ - - /** - * @dev a mapping of interface id to whether or not it's supported - */ - mapping(bytes4 => bool) internal supportedInterfaces; - - /** - * @dev A contract implementing SupportsInterfaceWithLookup - * implement ERC165 itself - */ - constructor() - public - { - _registerInterface(InterfaceId_ERC165); - } - - /** - * @dev implement supportsInterface(bytes4) using a lookup table - */ - function supportsInterface(bytes4 _interfaceId) - external - view - returns (bool) - { - return supportedInterfaces[_interfaceId]; - } - - /** - * @dev private method for registering an interface - */ - function _registerInterface(bytes4 _interfaceId) - internal - { - require(_interfaceId != 0xffffffff); - supportedInterfaces[_interfaceId] = true; - } -} - - -// Dependency file: @evolutionland/common/contracts/interfaces/IMintableERC20.sol - -// pragma solidity ^0.4.23; - -contract IMintableERC20 { - - function mint(address _to, uint256 _value) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/ISettingsRegistry.sol - -// pragma solidity ^0.4.24; - -contract ISettingsRegistry { - enum SettingsValueTypes { NONE, UINT, STRING, ADDRESS, BYTES, BOOL, INT } - - function uintOf(bytes32 _propertyName) public view returns (uint256); - - function stringOf(bytes32 _propertyName) public view returns (string); - - function addressOf(bytes32 _propertyName) public view returns (address); - - function bytesOf(bytes32 _propertyName) public view returns (bytes); - - function boolOf(bytes32 _propertyName) public view returns (bool); - - function intOf(bytes32 _propertyName) public view returns (int); - - function setUintProperty(bytes32 _propertyName, uint _value) public; - - function setStringProperty(bytes32 _propertyName, string _value) public; - - function setAddressProperty(bytes32 _propertyName, address _value) public; - - function setBytesProperty(bytes32 _propertyName, bytes _value) public; - - function setBoolProperty(bytes32 _propertyName, bool _value) public; - - function setIntProperty(bytes32 _propertyName, int _value) public; - - function getValueTypeOf(bytes32 _propertyName) public view returns (uint /* SettingsValueTypes */ ); - - event ChangeProperty(bytes32 indexed _propertyName, uint256 _type); -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IAuthority.sol - -// pragma solidity ^0.4.24; - -contract IAuthority { - function canCall( - address src, address dst, bytes4 sig - ) public view returns (bool); -} - -// Dependency file: @evolutionland/common/contracts/DSAuth.sol - -// pragma solidity ^0.4.24; - -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/IAuthority.sol'; - -contract DSAuthEvents { - event LogSetAuthority (address indexed authority); - event LogSetOwner (address indexed owner); -} - -/** - * @title DSAuth - * @dev The DSAuth contract is reference implement of https://github.com/dapphub/ds-auth - * But in the isAuthorized method, the src from address(this) is remove for safty concern. - */ -contract DSAuth is DSAuthEvents { - IAuthority public authority; - address public owner; - - constructor() public { - owner = msg.sender; - emit LogSetOwner(msg.sender); - } - - function setOwner(address owner_) - public - auth - { - owner = owner_; - emit LogSetOwner(owner); - } - - function setAuthority(IAuthority authority_) - public - auth - { - authority = authority_; - emit LogSetAuthority(authority); - } - - modifier auth { - require(isAuthorized(msg.sender, msg.sig)); - _; - } - - modifier onlyOwner() { - require(msg.sender == owner); - _; - } - - function isAuthorized(address src, bytes4 sig) internal view returns (bool) { - if (src == owner) { - return true; - } else if (authority == IAuthority(0)) { - return false; - } else { - return authority.canCall(src, this, sig); - } - } -} - - -// Dependency file: @evolutionland/common/contracts/interfaces/IInterstellarEncoder.sol - -// pragma solidity ^0.4.24; - -contract IInterstellarEncoder { - uint256 constant CLEAR_HIGH = 0x00000000000000000000000000000000ffffffffffffffffffffffffffffffff; - - uint256 public constant MAGIC_NUMBER = 42; // Interstellar Encoding Magic Number. - uint256 public constant CHAIN_ID = 1; // Ethereum mainet. - uint256 public constant CURRENT_LAND = 1; // 1 is Atlantis, 0 is NaN. - - enum ObjectClass { - NaN, - LAND, - APOSTLE, - OBJECT_CLASS_COUNT - } - - function registerNewObjectClass(address _objectContract, uint8 objectClass) public; - - function registerNewTokenContract(address _tokenAddress) public; - - function encodeTokenId(address _tokenAddress, uint8 _objectClass, uint128 _objectIndex) public view returns (uint256 _tokenId); - - function encodeTokenIdForObjectContract( - address _tokenAddress, address _objectContract, uint128 _objectId) public view returns (uint256 _tokenId); - - function getContractAddress(uint256 _tokenId) public view returns (address); - - function getObjectId(uint256 _tokenId) public view returns (uint128 _objectId); - - function getObjectClass(uint256 _tokenId) public view returns (uint8); - - function getObjectAddress(uint256 _tokenId) public view returns (address); -} - -// Dependency file: @evolutionland/common/contracts/interfaces/ITokenUse.sol - -// pragma solidity ^0.4.24; - -contract ITokenUse { - uint48 public constant MAX_UINT48_TIME = 281474976710655; - - function isObjectInHireStage(uint256 _tokenId) public view returns (bool); - - function isObjectReadyToUse(uint256 _tokenId) public view returns (bool); - - function getTokenUser(uint256 _tokenId) public view returns (address); - - function createTokenUseOffer(uint256 _tokenId, uint256 _duration, uint256 _price, address _acceptedActivity) public; - - function cancelTokenUseOffer(uint256 _tokenId) public; - - function takeTokenUseOffer(uint256 _tokenId) public; - - function addActivity(uint256 _tokenId, address _user, uint256 _endTime) public; - - function removeActivity(uint256 _tokenId, address _user) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IActivity.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - -contract IActivity is ERC165 { - bytes4 internal constant InterfaceId_IActivity = 0x6086e7f8; - /* - * 0x6086e7f8 === - * bytes4(keccak256('activityStopped(uint256)')) - */ - - function activityStopped(uint256 _tokenId) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IMinerObject.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/introspection/ERC165.sol"; - -contract IMinerObject is ERC165 { - bytes4 internal constant InterfaceId_IMinerObject = 0x64272b75; - - /* - * 0x64272b752 === - * bytes4(keccak256('strengthOf(uint256,address)')) - */ - - function strengthOf(uint256 _tokenId, address _resourceToken, uint256 _landTokenId) public view returns (uint256); - -} - -// Dependency file: contracts/interfaces/ILandBase.sol - -// pragma solidity ^0.4.24; - -contract ILandBase { - - /* - * Event - */ - event ModifiedResourceRate(uint indexed tokenId, address resourceToken, uint16 newResourceRate); - event HasboxSetted(uint indexed tokenId, bool hasBox); - - event ChangedReourceRateAttr(uint indexed tokenId, uint256 attr); - - event ChangedFlagMask(uint indexed tokenId, uint256 newFlagMask); - - event CreatedNewLand(uint indexed tokenId, int x, int y, address beneficiary, uint256 resourceRateAttr, uint256 mask); - - function defineResouceTokenRateAttrId(address _resourceToken, uint8 _attrId) public; - - function setHasBox(uint _landTokenID, bool isHasBox) public; - function isReserved(uint256 _tokenId) public view returns (bool); - function isSpecial(uint256 _tokenId) public view returns (bool); - function isHasBox(uint256 _tokenId) public view returns (bool); - - function getResourceRateAttr(uint _landTokenId) public view returns (uint256); - function setResourceRateAttr(uint _landTokenId, uint256 _newResourceRateAttr) public; - - function getResourceRate(uint _landTokenId, address _resouceToken) public view returns (uint16); - function setResourceRate(uint _landTokenID, address _resourceToken, uint16 _newResouceRate) public; - - function getFlagMask(uint _landTokenId) public view returns (uint256); - - function setFlagMask(uint _landTokenId, uint256 _newFlagMask) public; - - function resourceToken2RateAttrId(address _resourceToken) external view returns (uint256); -} - - -// Dependency file: contracts/interfaces/IMetaDataTeller.sol - -// pragma solidity ^0.4.24; - -interface IMetaDataTeller { - function addTokenMeta( - address _token, - uint16 _grade, - uint112 _strengthRate - ) external; - - //0xf666196d - function getMetaData(address _token, uint256 _id) - external - view - returns ( - uint16, - uint16, - uint16 - ); - - //0x7999a5cf - function getPrefer(address _token) external view returns (uint256); - - //0x33281815 - function getRate( - address _token, - uint256 _id, - uint256 _index - ) external view returns (uint256); -} - - -// Root file: contracts/LandResourceV5.sol - -pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/math/SafeMath.sol"; -// import "openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; -// import "openzeppelin-solidity/contracts/introspection/SupportsInterfaceWithLookup.sol"; -// import "@evolutionland/common/contracts/interfaces/IMintableERC20.sol"; -// import "@evolutionland/common/contracts/interfaces/ISettingsRegistry.sol"; -// import "@evolutionland/common/contracts/DSAuth.sol"; -// import "@evolutionland/common/contracts/interfaces/IInterstellarEncoder.sol"; -// import "@evolutionland/common/contracts/interfaces/ITokenUse.sol"; -// import "@evolutionland/common/contracts/interfaces/IActivity.sol"; -// import "@evolutionland/common/contracts/interfaces/IMinerObject.sol"; -// import "contracts/interfaces/ILandBase.sol"; -// import "contracts/interfaces/IMetaDataTeller.sol"; - -contract LandResourceV5 is SupportsInterfaceWithLookup, DSAuth, IActivity { - using SafeMath for *; - - // For every seconds, the speed will decrease by current speed multiplying (DENOMINATOR_in_seconds - seconds) / DENOMINATOR_in_seconds - // resource will decrease 1/10000 every day. - uint256 public constant DENOMINATOR = 10000; - - uint256 public constant TOTAL_SECONDS = DENOMINATOR * (1 days); - - bool private singletonLock = false; - - ISettingsRegistry public registry; - - uint256 public resourceReleaseStartTime; - - // TODO: move to global settings contract. - uint256 public attenPerDay = 1; - uint256 public recoverAttenPerDay = 20; - - // Struct for recording resouces on land which have already been pinged. - // 金, Evolution Land Gold - // 木, Evolution Land Wood - // 水, Evolution Land Water - // 火, Evolution Land fire - // 土, Evolution Land Silicon - struct ResourceMineState { - mapping(address => uint256) mintedBalance; - mapping(address => uint256[]) miners; - mapping(address => uint256) totalMinerStrength; - uint256 lastUpdateSpeedInSeconds; - uint256 lastDestoryAttenInSeconds; - uint256 industryIndex; - uint128 lastUpdateTime; - uint64 totalMiners; - uint64 maxMiners; - } - - struct MinerStatus { - uint256 landTokenId; - address resource; - uint64 indexInResource; - } - - mapping(uint256 => ResourceMineState) public land2ResourceMineState; - mapping(uint256 => MinerStatus) public miner2Index; - - /* - * Event - */ - - event StartMining( - uint256 minerTokenId, - uint256 landId, - address _resource, - uint256 strength - ); - event StopMining( - uint256 minerTokenId, - uint256 landId, - address _resource, - uint256 strength - ); - event ResourceClaimed( - address owner, - uint256 landTokenId, - uint256 goldBalance, - uint256 woodBalance, - uint256 waterBalance, - uint256 fireBalance, - uint256 soilBalance - ); - event UpdateMiningStrengthWhenStop( - uint256 apostleTokenId, - uint256 landId, - uint256 strength - ); - event UpdateMiningStrengthWhenStart( - uint256 apostleTokenId, - uint256 landId, - uint256 strength - ); - - // v5 add begin - event StartBarMining( - uint256 barIndex, - uint256 landId, - address resource, - uint256 rate - ); - event StopBarMining(uint256 barIndex, uint256 landId, address rate); - event LandResourceClaimed( - address owner, - uint256 landId, - uint256 goldBalance, - uint256 woodBalance, - uint256 waterBalance, - uint256 fireBalance, - uint256 soilBalance - ); - event ItemResourceClaimed( - address owner, - address itemToken, - uint256 itemTokenId, - uint256 goldBalance, - uint256 woodBalance, - uint256 waterBalance, - uint256 fireBalance, - uint256 soilBalance - ); - - // land item bar - event Equip( - uint256 indexed tokenId, - address resource, - uint256 index, - address staker, - address token, - uint256 id - ); - event Divest( - uint256 indexed tokenId, - address resource, - uint256 index, - address staker, - address token, - uint256 id - ); - - // 0x434f4e54524143545f4c414e445f424153450000000000000000000000000000 - bytes32 public constant CONTRACT_LAND_BASE = "CONTRACT_LAND_BASE"; - - // 0x434f4e54524143545f474f4c445f45524332305f544f4b454e00000000000000 - bytes32 public constant CONTRACT_GOLD_ERC20_TOKEN = - "CONTRACT_GOLD_ERC20_TOKEN"; - - // 0x434f4e54524143545f574f4f445f45524332305f544f4b454e00000000000000 - bytes32 public constant CONTRACT_WOOD_ERC20_TOKEN = - "CONTRACT_WOOD_ERC20_TOKEN"; - - // 0x434f4e54524143545f57415445525f45524332305f544f4b454e000000000000 - bytes32 public constant CONTRACT_WATER_ERC20_TOKEN = - "CONTRACT_WATER_ERC20_TOKEN"; - - // 0x434f4e54524143545f464952455f45524332305f544f4b454e00000000000000 - bytes32 public constant CONTRACT_FIRE_ERC20_TOKEN = - "CONTRACT_FIRE_ERC20_TOKEN"; - - // 0x434f4e54524143545f534f494c5f45524332305f544f4b454e00000000000000 - bytes32 public constant CONTRACT_SOIL_ERC20_TOKEN = - "CONTRACT_SOIL_ERC20_TOKEN"; - - // 0x434f4e54524143545f494e5445525354454c4c41525f454e434f444552000000 - bytes32 public constant CONTRACT_INTERSTELLAR_ENCODER = - "CONTRACT_INTERSTELLAR_ENCODER"; - - // 0x434f4e54524143545f4f424a4543545f4f574e45525348495000000000000000 - bytes32 public constant CONTRACT_OBJECT_OWNERSHIP = - "CONTRACT_OBJECT_OWNERSHIP"; - - // 0x434f4e54524143545f544f4b454e5f5553450000000000000000000000000000 - bytes32 public constant CONTRACT_TOKEN_USE = "CONTRACT_TOKEN_USE"; - - //0x4655524e4143455f4954454d5f4d494e455f4645450000000000000000000000 - bytes32 public constant FURNACE_ITEM_MINE_FEE = "FURNACE_ITEM_MINE_FEE"; - - // 0x434f4e54524143545f4d455441444154415f54454c4c45520000000000000000 - bytes32 public constant CONTRACT_METADATA_TELLER = - "CONTRACT_METADATA_TELLER"; - - // 0x55494e545f4954454d4241525f50524f544543545f504552494f440000000000 - bytes32 public constant UINT_ITEMBAR_PROTECT_PERIOD = - "UINT_ITEMBAR_PROTECT_PERIOD"; - - // rate precision - uint128 public constant RATE_PRECISION = 10**8; - - uint256 maxMiners; - - // (itemTokenAddress => (itemTokenId => (resourceAddress => mined balance))) - mapping(address => mapping(uint256 => mapping(address => uint256))) - public itemMinedBalance; - - // (landTokenId => (resourceAddress => (landBarIndex => itemEnhancedRate))) - mapping(uint256 => mapping(address => mapping(uint256 => uint256))) - public land2BarRate; - - // land bar - struct Bar { - address staker; - address token; - uint256 id; - address resource; - } - - // bar status - struct Status { - address staker; - uint256 tokenId; - uint256 index; - } - - // max land bar amount - uint256 public maxAmount; - // (landTokenId => (landBarIndex => BAR)) - mapping(uint256 => mapping(uint256 => Bar)) public landId2Bars; - // (itemTokenAddress => (itemTokenId => STATUS)) - mapping(address => mapping(uint256 => Status)) public itemId2Status; - // (itemTokenAddress => (itemTokenId => itemProtectPeriod)) - mapping(address => mapping(uint256 => uint256)) public protectPeriod; - // v5 add end - - /* - * Modifiers - */ - modifier singletonLockCall() { - require(!singletonLock, "Only can call once"); - _; - singletonLock = true; - } - - function initializeContract( - address _registry, - uint256 _resourceReleaseStartTime - ) public singletonLockCall { - // Ownable constructor - owner = msg.sender; - emit LogSetOwner(msg.sender); - - registry = ISettingsRegistry(_registry); - - resourceReleaseStartTime = _resourceReleaseStartTime; - - _registerInterface(InterfaceId_IActivity); - } - - // get amount of speed uint at this moment - function _getReleaseSpeedInSeconds(uint256 _tokenId, uint256 _time) - internal - view - returns (uint256 currentSpeed) - { - require(_time >= resourceReleaseStartTime, "Should after release time"); - require( - _time >= land2ResourceMineState[_tokenId].lastUpdateTime, - "Should after release last update time" - ); - - // after 10000 days from start - // the resource release speed decreases to 0 - if (TOTAL_SECONDS < _time - resourceReleaseStartTime) { - return 0; - } - - // max amount of speed unit of _tokenId for now - // suppose that speed_uint = 1 in this function - uint256 availableSpeedInSeconds = - TOTAL_SECONDS.sub(_time - resourceReleaseStartTime); - return availableSpeedInSeconds; - // // time from last update - // uint256 timeBetween = - // _time - land2ResourceMineState[_tokenId].lastUpdateTime; - - // // the recover speed is 20/10000, 20 times. - // // recoveryRate overall from lasUpdateTime til now + amount of speed uint at lastUpdateTime - // uint256 nextSpeedInSeconds = - // land2ResourceMineState[_tokenId].lastUpdateSpeedInSeconds + - // timeBetween * - // recoverAttenPerDay; - // // destroyRate overall from lasUpdateTime til now amount of speed uint at lastUpdateTime - // uint256 destroyedSpeedInSeconds = - // timeBetween * - // land2ResourceMineState[_tokenId].lastDestoryAttenInSeconds; - - // if (nextSpeedInSeconds < destroyedSpeedInSeconds) { - // nextSpeedInSeconds = 0; - // } else { - // nextSpeedInSeconds = nextSpeedInSeconds - destroyedSpeedInSeconds; - // } - - // if (nextSpeedInSeconds > availableSpeedInSeconds) { - // nextSpeedInSeconds = availableSpeedInSeconds; - // } - - // return nextSpeedInSeconds; - } - - function getReleaseSpeed( - uint256 _tokenId, - address _resource, - uint256 _time - ) public view returns (uint256 currentSpeed) { - return - ILandBase(registry.addressOf(CONTRACT_LAND_BASE)) - .getResourceRate(_tokenId, _resource) - .mul(_getReleaseSpeedInSeconds(_tokenId, _time)) - .mul(1 ether) - .div(TOTAL_SECONDS); - } - - function _getMinableBalance( - uint256 _tokenId, - address _resource, - uint256 _currentTime, - uint256 _lastUpdateTime - ) public view returns (uint256 minableBalance) { - uint256 speed_in_current_period = - ILandBase(registry.addressOf(CONTRACT_LAND_BASE)) - .getResourceRate(_tokenId, _resource) - .mul( - _getReleaseSpeedInSeconds( - _tokenId, - ((_currentTime + _lastUpdateTime) / 2) - ) - ) - .mul(1 ether) - .div(1 days) - .div(TOTAL_SECONDS); - - // calculate the area of trapezoid - minableBalance = speed_in_current_period.mul( - _currentTime - _lastUpdateTime - ); - } - - function _getMaxMineBalance( - uint256 _tokenId, - address _resource, - uint256 _currentTime, - uint256 _lastUpdateTime - ) internal view returns (uint256) { - // totalMinerStrength is in wei - return - getTotalMiningStrength(_tokenId, _resource) - .mul(_currentTime - _lastUpdateTime) - .div(1 days); - } - - function setMaxMiners(uint256 _maxMiners) public auth { - require(_maxMiners > maxMiners, "Land: INVALID_MAXMINERS"); - maxMiners = _maxMiners; - } - - function mine(uint256 _landTokenId) public { - _mineAllResource( - _landTokenId, - registry.addressOf(CONTRACT_GOLD_ERC20_TOKEN), - registry.addressOf(CONTRACT_WOOD_ERC20_TOKEN), - registry.addressOf(CONTRACT_WATER_ERC20_TOKEN), - registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN), - registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN) - ); - } - - function _mineAllResource( - uint256 _landTokenId, - address _gold, - address _wood, - address _water, - address _fire, - address _soil - ) internal { - require( - IInterstellarEncoder( - registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER) - ) - .getObjectClass(_landTokenId) == 1, - "Token must be land." - ); - - // v5 remove - // if (land2ResourceMineState[_landTokenId].lastUpdateTime == 0) { - // land2ResourceMineState[_landTokenId].lastUpdateTime = uint128( - // resourceReleaseStartTime - // ); - // land2ResourceMineState[_landTokenId] - // .lastUpdateSpeedInSeconds = TOTAL_SECONDS; - // } - - _mineResource(_landTokenId, _gold); - _mineResource(_landTokenId, _wood); - _mineResource(_landTokenId, _water); - _mineResource(_landTokenId, _fire); - _mineResource(_landTokenId, _soil); - - // v5 remove - // land2ResourceMineState[_landTokenId] - // .lastUpdateSpeedInSeconds = _getReleaseSpeedInSeconds( - // _landTokenId, - // now - // ); - - land2ResourceMineState[_landTokenId].lastUpdateTime = uint128(now); - } - - function _distribution( - uint256 _landId, - address _resource, - uint256 minedBalance, - uint256 barsRate - ) internal returns (uint256) { - uint256 landBalance = - minedBalance.mul(RATE_PRECISION).div(barsRate.add(RATE_PRECISION)); - uint256 barsBalance = minedBalance.sub(landBalance); - for (uint256 i = 0; i < maxAmount; i++) { - (address itemToken, uint256 itemId, address resouce) = - getBarItem(_landId, i); - if (itemToken != address(0) && resouce == _resource) { - uint256 barBalance = - barsBalance.mul(getBarRate(_landId, _resource, i)).div( - barsRate - ); - (barBalance, landBalance) = _payFee(barBalance, landBalance); - itemMinedBalance[itemToken][itemId][ - _resource - ] = getItemMinedBalance(itemToken, itemId, _resource).add( - barBalance - ); - } - } - return landBalance; - } - - function _payFee(uint256 barBalance, uint256 landBalance) - internal - view - returns (uint256, uint256) - { - uint256 fee = - barBalance.mul(registry.uintOf(FURNACE_ITEM_MINE_FEE)).div( - RATE_PRECISION - ); - barBalance = barBalance.sub(fee); - landBalance = landBalance.add(fee); - return (barBalance, landBalance); - } - - function _mineResource(uint256 _landId, address _resource) internal { - // the longest seconds to zero speed. - if (getLandMiningStrength(_landId, _resource) == 0) { - return; - } - uint256 minedBalance = _calculateMinedBalance(_landId, _resource, now); - if (minedBalance == 0) { - return; - } - - uint256 barsRate = getBarsRate(_landId, _resource); - uint256 landBalance = minedBalance; - if (barsRate > 0) { - // V5 yeild distribution - landBalance = _distribution( - _landId, - _resource, - minedBalance, - barsRate - ); - } - land2ResourceMineState[_landId].mintedBalance[ - _resource - ] = getLandMinedBalance(_landId, _resource).add(landBalance); - } - - function _calculateMinedBalance( - uint256 _landTokenId, - address _resourceToken, - uint256 _currentTime - ) internal view returns (uint256) { - uint256 currentTime = _currentTime; - - uint256 minedBalance; - uint256 minableBalance; - if (currentTime > (resourceReleaseStartTime + TOTAL_SECONDS)) { - currentTime = (resourceReleaseStartTime + TOTAL_SECONDS); - } - - uint256 lastUpdateTime = - land2ResourceMineState[_landTokenId].lastUpdateTime; - require(currentTime >= lastUpdateTime); - - if (lastUpdateTime >= (resourceReleaseStartTime + TOTAL_SECONDS)) { - minedBalance = 0; - minableBalance = 0; - } else { - minedBalance = _getMaxMineBalance( - _landTokenId, - _resourceToken, - currentTime, - lastUpdateTime - ); - minableBalance = _getMinableBalance( - _landTokenId, - _resourceToken, - currentTime, - lastUpdateTime - ); - } - - if (minedBalance > minableBalance) { - minedBalance = minableBalance; - } - - return minedBalance; - } - - // v5 remove - // function claimAllResource(uint256 _landTokenId) public { - // require( - // msg.sender == ownership.ownerOf(_landTokenId), - // "Must be the owner of the land" - // ); - - // _mineAllResource(_landTokenId, gold, wood, water, fire, soil); - - // uint256 goldBalance; - // uint256 woodBalance; - // uint256 waterBalance; - // uint256 fireBalance; - // uint256 soilBalance; - - // if (land2ResourceMineState[_landTokenId].mintedBalance[gold] > 0) { - // goldBalance = land2ResourceMineState[_landTokenId].mintedBalance[ - // gold - // ]; - // IMintableERC20(gold).mint(msg.sender, goldBalance); - // land2ResourceMineState[_landTokenId].mintedBalance[gold] = 0; - // } - - // if (land2ResourceMineState[_landTokenId].mintedBalance[wood] > 0) { - // woodBalance = land2ResourceMineState[_landTokenId].mintedBalance[ - // wood - // ]; - // IMintableERC20(wood).mint(msg.sender, woodBalance); - // land2ResourceMineState[_landTokenId].mintedBalance[wood] = 0; - // } - - // if (land2ResourceMineState[_landTokenId].mintedBalance[water] > 0) { - // waterBalance = land2ResourceMineState[_landTokenId].mintedBalance[ - // water - // ]; - // IMintableERC20(water).mint(msg.sender, waterBalance); - // land2ResourceMineState[_landTokenId].mintedBalance[water] = 0; - // } - - // if (land2ResourceMineState[_landTokenId].mintedBalance[fire] > 0) { - // fireBalance = land2ResourceMineState[_landTokenId].mintedBalance[ - // fire - // ]; - // IMintableERC20(fire).mint(msg.sender, fireBalance); - // land2ResourceMineState[_landTokenId].mintedBalance[fire] = 0; - // } - - // if (land2ResourceMineState[_landTokenId].mintedBalance[soil] > 0) { - // soilBalance = land2ResourceMineState[_landTokenId].mintedBalance[ - // soil - // ]; - // IMintableERC20(soil).mint(msg.sender, soilBalance); - // land2ResourceMineState[_landTokenId].mintedBalance[soil] = 0; - // } - - // emit ResourceClaimed( - // msg.sender, - // _landTokenId, - // goldBalance, - // woodBalance, - // waterBalance, - // fireBalance, - // soilBalance - // ); - // } - - // both for own _tokenId or hired one - function startMining( - uint256 _tokenId, - uint256 _landTokenId, - address _resource - ) public { - ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).addActivity( - _tokenId, - msg.sender, - 0 - ); - - // require the permission from land owner; - require( - msg.sender == - ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf( - _landTokenId - ), - "Must be the owner of the land" - ); - - // make sure that _tokenId won't be used repeatedly - require(miner2Index[_tokenId].landTokenId == 0); - - // update status! - mine(_landTokenId); - - uint256 _index = - land2ResourceMineState[_landTokenId].miners[_resource].length; - - land2ResourceMineState[_landTokenId].totalMiners += 1; - - // v5 remove - // if (land2ResourceMineState[_landTokenId].maxMiners == 0) { - // land2ResourceMineState[_landTokenId].maxMiners = 5; - // } - - require( - land2ResourceMineState[_landTokenId].totalMiners <= maxMiners, - "Land: EXCEED_MAXAMOUNT" - ); - - address miner = - IInterstellarEncoder( - registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER) - ) - .getObjectAddress(_tokenId); - uint256 strength = - IMinerObject(miner).strengthOf(_tokenId, _resource, _landTokenId); - - land2ResourceMineState[_landTokenId].miners[_resource].push(_tokenId); - land2ResourceMineState[_landTokenId].totalMinerStrength[ - _resource - ] += strength; - - miner2Index[_tokenId] = MinerStatus({ - landTokenId: _landTokenId, - resource: _resource, - indexInResource: uint64(_index) - }); - - emit StartMining(_tokenId, _landTokenId, _resource, strength); - } - - function batchStartMining( - uint256[] _tokenIds, - uint256[] _landTokenIds, - address[] _resources - ) public { - require( - _tokenIds.length == _landTokenIds.length && - _landTokenIds.length == _resources.length, - "input error" - ); - uint256 length = _tokenIds.length; - - for (uint256 i = 0; i < length; i++) { - startMining(_tokenIds[i], _landTokenIds[i], _resources[i]); - } - } - - function batchClaimLandResource(uint256[] _landTokenIds) public { - uint256 length = _landTokenIds.length; - - for (uint256 i = 0; i < length; i++) { - claimLandResource(_landTokenIds[i]); - } - } - - // Only trigger from Token Activity. - function activityStopped(uint256 _tokenId) public auth { - _stopMining(_tokenId); - } - - function stopMining(uint256 _tokenId) public { - ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).removeActivity( - _tokenId, - msg.sender - ); - } - - function _stopMining(uint256 _tokenId) internal { - // remove the miner from land2ResourceMineState; - uint64 minerIndex = miner2Index[_tokenId].indexInResource; - address resource = miner2Index[_tokenId].resource; - uint256 landTokenId = miner2Index[_tokenId].landTokenId; - - // update status! - mine(landTokenId); - - uint64 lastMinerIndex = - uint64( - land2ResourceMineState[landTokenId].miners[resource].length.sub( - 1 - ) - ); - uint256 lastMiner = - land2ResourceMineState[landTokenId].miners[resource][ - lastMinerIndex - ]; - - land2ResourceMineState[landTokenId].miners[resource][ - minerIndex - ] = lastMiner; - land2ResourceMineState[landTokenId].miners[resource][ - lastMinerIndex - ] = 0; - - land2ResourceMineState[landTokenId].miners[resource].length -= 1; - miner2Index[lastMiner].indexInResource = minerIndex; - - land2ResourceMineState[landTokenId].totalMiners -= 1; - - address miner = - IInterstellarEncoder( - registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER) - ) - .getObjectAddress(_tokenId); - uint256 strength = - IMinerObject(miner).strengthOf(_tokenId, resource, landTokenId); - - // for backward compatibility - // if strength can fluctuate some time in the future - if ( - land2ResourceMineState[landTokenId].totalMinerStrength[resource] != - 0 - ) { - if ( - land2ResourceMineState[landTokenId].totalMinerStrength[ - resource - ] > strength - ) { - land2ResourceMineState[landTokenId].totalMinerStrength[ - resource - ] = land2ResourceMineState[landTokenId].totalMinerStrength[ - resource - ] - .sub(strength); - } else { - land2ResourceMineState[landTokenId].totalMinerStrength[ - resource - ] = 0; - } - } - - if (land2ResourceMineState[landTokenId].totalMiners == 0) { - land2ResourceMineState[landTokenId].totalMinerStrength[ - resource - ] = 0; - } - - delete miner2Index[_tokenId]; - - emit StopMining(_tokenId, landTokenId, resource, strength); - } - - // v5 remove - // function getMinerOnLand( - // uint256 _landTokenId, - // address _resourceToken, - // uint256 _index - // ) public view returns (uint256) { - // return - // land2ResourceMineState[_landTokenId].miners[_resourceToken][_index]; - // } - - // function getTotalMiningStrength( - // uint256 _landTokenId, - // address _resourceToken - // ) public view returns (uint256) { - // return - // land2ResourceMineState[_landTokenId].totalMinerStrength[ - // _resourceToken - // ]; - // } - - // function availableResources( - // uint256 _landTokenId, - // address[5] _resourceTokens - // ) - // public - // view - // returns ( - // uint256, - // uint256, - // uint256, - // uint256, - // uint256 - // ) - // { - // uint256 availableGold = - // _calculateMinedBalance(_landTokenId, _resourceTokens[0], now) + - // land2ResourceMineState[_landTokenId].mintedBalance[ - // _resourceTokens[0] - // ]; - // uint256 availableWood = - // _calculateMinedBalance(_landTokenId, _resourceTokens[1], now) + - // land2ResourceMineState[_landTokenId].mintedBalance[ - // _resourceTokens[1] - // ]; - // uint256 availableWater = - // _calculateMinedBalance(_landTokenId, _resourceTokens[2], now) + - // land2ResourceMineState[_landTokenId].mintedBalance[ - // _resourceTokens[2] - // ]; - // uint256 availableFire = - // _calculateMinedBalance(_landTokenId, _resourceTokens[3], now) + - // land2ResourceMineState[_landTokenId].mintedBalance[ - // _resourceTokens[3] - // ]; - // uint256 availableSoil = - // _calculateMinedBalance(_landTokenId, _resourceTokens[4], now) + - // land2ResourceMineState[_landTokenId].mintedBalance[ - // _resourceTokens[4] - // ]; - - // return ( - // availableGold, - // availableWood, - // availableWater, - // availableFire, - // availableSoil - // ); - // } - - // V5 remove - // function mintedBalanceOnLand(uint256 _landTokenId, address _resourceToken) public view returns (uint256) { - // return land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken]; - // } - - // function landWorkingOn(uint256 _apostleTokenId) public view returns (uint256 landTokenId) { - // landTokenId = miner2Index[_apostleTokenId].landTokenId; - // } - - function _updateMinerStrength(uint256 _apostleTokenId, bool _isStop) - internal - returns (uint256, uint256) - { - // require that this apostle - uint256 landTokenId = landWorkingOn(_apostleTokenId); - require(landTokenId != 0, "this apostle is not mining."); - - address resource = miner2Index[_apostleTokenId].resource; - - address miner = - IInterstellarEncoder( - registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER) - ) - .getObjectAddress(_apostleTokenId); - uint256 strength = - IMinerObject(miner).strengthOf( - _apostleTokenId, - resource, - landTokenId - ); - - mine(landTokenId); - - if (_isStop) { - land2ResourceMineState[landTokenId].totalMinerStrength[ - resource - ] = land2ResourceMineState[landTokenId].totalMinerStrength[resource] - .sub(strength); - } else { - land2ResourceMineState[landTokenId].totalMinerStrength[ - resource - ] += strength; - } - - return (landTokenId, strength); - } - - // when a mirrorToken or a pet has tied to apostle - // we need to update status and remove this apostle from mining list first - // open authority to PetBase - // can only be called by PetBase - function updateMinerStrengthWhenStop(uint256 _apostleTokenId) public auth { - uint256 landTokenId; - uint256 strength; - (landTokenId, strength) = _updateMinerStrength(_apostleTokenId, true); - // _isStop == true - minus strength - // _isStop == false - add strength - emit UpdateMiningStrengthWhenStop( - _apostleTokenId, - landTokenId, - strength - ); - } - - function updateMinerStrengthWhenStart(uint256 _apostleTokenId) public auth { - uint256 landTokenId; - uint256 strength; - (landTokenId, strength) = _updateMinerStrength(_apostleTokenId, false); - // _isStop == true - minus strength - // _isStop == false - add strength - emit UpdateMiningStrengthWhenStart( - _apostleTokenId, - landTokenId, - strength - ); - } - - // V5 add - function getLandMinedBalance(uint256 _landId, address _resource) - public - view - returns (uint256) - { - return land2ResourceMineState[_landId].mintedBalance[_resource]; - } - - function getItemMinedBalance( - address _itemToken, - uint256 _itemId, - address _resource - ) public view returns (uint256) { - return itemMinedBalance[_itemToken][_itemId][_resource]; - } - - function getLandMiningStrength(uint256 _landId, address _resource) - public - view - returns (uint256) - { - return land2ResourceMineState[_landId].totalMinerStrength[_resource]; - } - - function getBarMiningStrength( - uint256 _landId, - address _resource, - uint256 _index - ) public view returns (uint256) { - return - getLandMiningStrength(_landId, _resource) - .mul(getBarRate(_landId, _resource, _index)) - .div(RATE_PRECISION); - } - - function getBarRate( - uint256 _landId, - address _resource, - uint256 _index - ) public view returns (uint256) { - return land2BarRate[_landId][_resource][_index]; - } - - function getBarsRate(uint256 _landId, address _resource) - public - view - returns (uint256 barsRate) - { - for (uint256 i = 0; i < maxAmount; i++) { - barsRate = barsRate.add(getBarRate(_landId, _resource, i)); - } - } - - function getBarsMiningStrength(uint256 _landId, address _resource) - public - view - returns (uint256 barsMiningStrength) - { - return - getLandMiningStrength(_landId, _resource) - .mul(getBarsRate(_landId, _resource)) - .div(RATE_PRECISION); - } - - function getTotalMiningStrength(uint256 _landId, address _resource) - public - view - returns (uint256) - { - return - getLandMiningStrength(_landId, _resource).add( - getBarsMiningStrength(_landId, _resource) - ); - } - - function getMinerOnLand( - uint256 _landId, - address _resource, - uint256 _index - ) public view returns (uint256) { - return land2ResourceMineState[_landId].miners[_resource][_index]; - } - - function landWorkingOn(uint256 _apostleTokenId) - public - view - returns (uint256 landId) - { - landId = miner2Index[_apostleTokenId].landTokenId; - } - - function _getBarRateByIndex( - uint256 _landId, - address _resource, - uint256 _index - ) internal view returns (uint256) { - return enhanceStrengthRateByIndex(_resource, _landId, _index); - } - - function _startBarMining( - uint256 _index, - uint256 _landId, - address _resource - ) internal { - uint256 rate = _getBarRateByIndex(_landId, _resource, _index); - land2BarRate[_landId][_resource][_index] = rate; - emit StartBarMining(_index, _landId, _resource, rate); - } - - function _stopBarMinig( - uint256 _index, - uint256 _landId, - address _resource - ) internal { - delete land2BarRate[_landId][_resource][_index]; - emit StopBarMining(_index, _landId, _resource); - } - - function _claimItemResource( - address _itemToken, - uint256 _itemId, - address _resource - ) internal returns (uint256) { - uint256 balance = getItemMinedBalance(_itemToken, _itemId, _resource); - if (balance > 0) { - IMintableERC20(_resource).mint(msg.sender, balance); - itemMinedBalance[_itemToken][_itemId][_resource] = 0; - return balance; - } else { - return 0; - } - } - - function claimItemResource(address _itemToken, uint256 _itemId) public { - (address staker, uint256 landId) = getLandIdByItem(_itemToken, _itemId); - if (staker == address(0) && landId == 0) { - require( - ERC721(_itemToken).ownerOf(_itemId) == msg.sender, - "Land: ONLY_ITEM_ONWER" - ); - } else { - require(staker == msg.sender, "Land: ONLY_ITEM_STAKER"); - mine(landId); - } - - address gold = registry.addressOf(CONTRACT_GOLD_ERC20_TOKEN); - address wood = registry.addressOf(CONTRACT_WOOD_ERC20_TOKEN); - address water = registry.addressOf(CONTRACT_WATER_ERC20_TOKEN); - address fire = registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN); - address soil = registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN); - uint256 goldBalance = _claimItemResource(_itemToken, _itemId, gold); - uint256 woodBalance = _claimItemResource(_itemToken, _itemId, wood); - uint256 waterBalance = _claimItemResource(_itemToken, _itemId, water); - uint256 fireBalance = _claimItemResource(_itemToken, _itemId, fire); - uint256 soilBalance = _claimItemResource(_itemToken, _itemId, soil); - - emit ItemResourceClaimed( - msg.sender, - _itemToken, - _itemId, - goldBalance, - woodBalance, - waterBalance, - fireBalance, - soilBalance - ); - } - - function _claimLandResource(uint256 _landId, address _resource) - internal - returns (uint256) - { - uint256 balance = getLandMinedBalance(_landId, _resource); - if (balance > 0) { - IMintableERC20(_resource).mint(msg.sender, balance); - land2ResourceMineState[_landId].mintedBalance[_resource] = 0; - return balance; - } else { - return 0; - } - } - - function claimLandResource(uint256 _landId) public { - require( - msg.sender == - ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf( - _landId - ), - "Land: ONLY_LANDER" - ); - - address gold = registry.addressOf(CONTRACT_GOLD_ERC20_TOKEN); - address wood = registry.addressOf(CONTRACT_WOOD_ERC20_TOKEN); - address water = registry.addressOf(CONTRACT_WATER_ERC20_TOKEN); - address fire = registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN); - address soil = registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN); - _mineAllResource(_landId, gold, wood, water, fire, soil); - - uint256 goldBalance = _claimLandResource(_landId, gold); - uint256 woodBalance = _claimLandResource(_landId, wood); - uint256 waterBalance = _claimLandResource(_landId, water); - uint256 fireBalance = _claimLandResource(_landId, fire); - uint256 soilBalance = _claimLandResource(_landId, soil); - - emit LandResourceClaimed( - msg.sender, - _landId, - goldBalance, - woodBalance, - waterBalance, - fireBalance, - soilBalance - ); - } - - function _calculateResources( - address _itemToken, - uint256 _itemId, - uint256 _landId, - address _resource, - uint256 _minedBalance - ) internal view returns (uint256 landBalance, uint256 barResource) { - uint256 barsRate = getBarsRate(_landId, _resource); - // V5 yeild distribution - landBalance = _minedBalance.mul(RATE_PRECISION).div( - barsRate.add(RATE_PRECISION) - ); - if (barsRate > 0) { - uint256 barsBalance = _minedBalance.sub(landBalance); - for (uint256 i = 0; i < maxAmount; i++) { - uint256 barBalance = - barsBalance.mul(getBarRate(_landId, _resource, i)).div( - barsRate - ); - (barBalance, landBalance) = _payFee(barBalance, landBalance); - (address itemToken, uint256 itemId, ) = getBarItem(_landId, i); - if (_itemId == itemId && _itemToken == itemToken) { - barResource = barResource.add(barBalance); - } - } - } - } - - function availableLandResources( - uint256 _landId, - address[] memory _resources - ) public view returns (uint256[] memory) { - uint256[] memory availables = new uint256[](_resources.length); - for (uint256 i = 0; i < _resources.length; i++) { - uint256 mined = _calculateMinedBalance(_landId, _resources[i], now); - (uint256 available, ) = - _calculateResources( - address(0), - 0, - _landId, - _resources[i], - mined - ); - availables[i] = available.add( - getLandMinedBalance(_landId, _resources[i]) - ); - } - return availables; - } - - function availableItemResources( - address _itemToken, - uint256 _itemId, - address[] memory _resources - ) public view returns (uint256[] memory) { - uint256[] memory availables = new uint256[](_resources.length); - for (uint256 i = 0; i < _resources.length; i++) { - (address staker, uint256 landId) = - getLandIdByItem(_itemToken, _itemId); - uint256 available = 0; - if (staker != address(0) && landId != 0) { - uint256 mined = - _calculateMinedBalance(landId, _resources[i], now); - (, uint256 availableItem) = - _calculateResources( - _itemToken, - _itemId, - landId, - _resources[i], - mined - ); - available = available.add(availableItem); - } - available = available.add( - getItemMinedBalance(_itemToken, _itemId, _resources[i]) - ); - availables[i] = available; - } - return availables; - } - - function isNotProtect(address _token, uint256 _id) - public - view - returns (bool) - { - return protectPeriod[_token][_id] < now; - } - - function getBarItem(uint256 _tokenId, uint256 _index) - public - view - returns ( - address, - uint256, - address - ) - { - require(_index < maxAmount, "Furnace: INDEX_FORBIDDEN."); - return ( - landId2Bars[_tokenId][_index].token, - landId2Bars[_tokenId][_index].id, - landId2Bars[_tokenId][_index].resource - ); - } - - function getLandIdByItem(address _item, uint256 _itemId) - public - view - returns (address, uint256) - { - return ( - itemId2Status[_item][_itemId].staker, - itemId2Status[_item][_itemId].tokenId - ); - } - - /** - @dev Equip function, A NFT can equip to EVO Bar (LandBar or ApostleBar). - @param _tokenId Token Id which to be quiped. - @param _resource Which resouce appply to. - @param _index Index of the Bar. - @param _token Token address which to quip. - @param _id Token Id which to quip. - */ - function equip( - uint256 _tokenId, - address _resource, - uint256 _index, - address _token, - uint256 _id - ) public { - _equip(_tokenId, _resource, _index, _token, _id); - } - - function _equip( - uint256 _tokenId, - address _resource, - uint256 _index, - address _token, - uint256 _id - ) internal { - beforeEquip(_tokenId, _resource); - IMetaDataTeller teller = - IMetaDataTeller(registry.addressOf(CONTRACT_METADATA_TELLER)); - uint256 resourceId = - ILandBase(registry.addressOf(CONTRACT_LAND_BASE)) - .resourceToken2RateAttrId(_resource); - require(resourceId > 0 && resourceId < 6, "Furnace: INVALID_RESOURCE"); - require( - IInterstellarEncoder( - registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER) - ) - .getObjectClass(_tokenId) == 1, - "Funace: ONLY_LAND" - ); - (uint16 objClassExt, uint16 class, uint16 grade) = - teller.getMetaData(_token, _id); - require(objClassExt > 0, "Furnace: PERMISSION"); - require(_index < maxAmount, "Furnace: INDEX_FORBIDDEN"); - Bar storage bar = landId2Bars[_tokenId][_index]; - if (bar.token != address(0)) { - require(isNotProtect(bar.token, bar.id), "Furnace: PROTECT_PERIOD"); - (, uint16 originClass, uint16 originGrade) = - teller.getMetaData(bar.token, bar.id); - require( - class > originClass || - (class == originClass && grade > originGrade) || - ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)) - .ownerOf(_tokenId) == - msg.sender, - "Furnace: FORBIDDEN" - ); - //TODO:: safe transfer - ERC721(bar.token).transferFrom(address(this), bar.staker, bar.id); - } - ERC721(_token).transferFrom(msg.sender, address(this), _id); - bar.staker = msg.sender; - bar.token = _token; - bar.id = _id; - bar.resource = _resource; - itemId2Status[bar.token][bar.id] = Status({ - staker: bar.staker, - tokenId: _tokenId, - index: _index - }); - if (isNotProtect(bar.token, bar.id)) { - protectPeriod[bar.token][bar.id] = _calculateProtectPeriod( - bar - .token, - bar - .id, - class - ) - .add(now); - } - afterEquiped(_index, _tokenId, _resource); - emit Equip(_tokenId, _resource, _index, bar.staker, bar.token, bar.id); - } - - function _calculateProtectPeriod( - address _token, - uint256 _id, - uint16 _class - ) internal view returns (uint256) { - uint256 baseProtectPeriod = - registry.uintOf(UINT_ITEMBAR_PROTECT_PERIOD); - return baseProtectPeriod.add(uint256(_class).mul(baseProtectPeriod)); - } - - function beforeEquip(uint256 _landTokenId, address _resource) internal { - if (getLandMiningStrength(_landTokenId, _resource) > 0) { - mine(_landTokenId); - } - } - - function afterEquiped( - uint256 _index, - uint256 _landTokenId, - address _resource - ) internal { - _startBarMining(_index, _landTokenId, _resource); - } - - function afterDivested( - uint256 _index, - uint256 _landTokenId, - address _resource - ) internal { - if (getLandMiningStrength(_landTokenId, _resource) > 0) { - mine(_landTokenId); - } - _stopBarMinig(_index, _landTokenId, _resource); - } - - /** - @dev Divest function, A NFT can Divest from EVO Bar (LandBar or ApostleBar). - @param _tokenId Token Id which to be unquiped. - @param _index Index of the Bar. - */ - function divest(uint256 _tokenId, uint256 _index) public { - _divest(_tokenId, _index); - } - - function _divest(uint256 _tokenId, uint256 _index) internal { - Bar memory bar = landId2Bars[_tokenId][_index]; - require(bar.token != address(0), "Furnace: EMPTY"); - require(bar.staker == msg.sender, "Furnace: FORBIDDEN"); - ERC721(bar.token).transferFrom(address(this), bar.staker, bar.id); - afterDivested(_index, _tokenId, bar.resource); - //clean - delete itemId2Status[bar.token][bar.id]; - delete landId2Bars[_tokenId][_index]; - emit Divest( - _tokenId, - bar.resource, - _index, - bar.staker, - bar.token, - bar.id - ); - } - - function setMaxAmount(uint256 _maxAmount) public auth { - require(_maxAmount > maxAmount, "Furnace: INVALID_MAXAMOUNT"); - maxAmount = _maxAmount; - } - - function enhanceStrengthRateByIndex( - address _resource, - uint256 _tokenId, - uint256 _index - ) public view returns (uint256) { - Bar storage bar = landId2Bars[_tokenId][_index]; - if (bar.token == address(0)) { - return 0; - } - IMetaDataTeller teller = - IMetaDataTeller(registry.addressOf(CONTRACT_METADATA_TELLER)); - uint256 resourceId = - ILandBase(registry.addressOf(CONTRACT_LAND_BASE)) - .resourceToken2RateAttrId(_resource); - return teller.getRate(bar.token, bar.id, resourceId); - } - - function enhanceStrengthRateOf(address _resource, uint256 _tokenId) - external - view - returns (uint256) - { - uint256 rate; - for (uint256 i = 0; i < maxAmount; i++) { - rate = rate.add(enhanceStrengthRateByIndex(_resource, _tokenId, i)); - } - return rate; - } -} diff --git a/flat/LandSettingIds.sol b/flat/LandSettingIds.sol deleted file mode 100644 index 8d365a7..0000000 --- a/flat/LandSettingIds.sol +++ /dev/null @@ -1,71 +0,0 @@ -// Dependency file: @evolutionland/common/contracts/SettingIds.sol - -// pragma solidity ^0.4.24; - -/** - Id definitions for SettingsRegistry.sol - Can be used in conjunction with the settings registry to get properties -*/ -contract SettingIds { - bytes32 public constant CONTRACT_RING_ERC20_TOKEN = "CONTRACT_RING_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_KTON_ERC20_TOKEN = "CONTRACT_KTON_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_GOLD_ERC20_TOKEN = "CONTRACT_GOLD_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_WOOD_ERC20_TOKEN = "CONTRACT_WOOD_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_WATER_ERC20_TOKEN = "CONTRACT_WATER_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_FIRE_ERC20_TOKEN = "CONTRACT_FIRE_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_SOIL_ERC20_TOKEN = "CONTRACT_SOIL_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_OBJECT_OWNERSHIP = "CONTRACT_OBJECT_OWNERSHIP"; - - bytes32 public constant CONTRACT_TOKEN_LOCATION = "CONTRACT_TOKEN_LOCATION"; - - bytes32 public constant CONTRACT_LAND_BASE = "CONTRACT_LAND_BASE"; - - bytes32 public constant CONTRACT_USER_POINTS = "CONTRACT_USER_POINTS"; - - bytes32 public constant CONTRACT_INTERSTELLAR_ENCODER = "CONTRACT_INTERSTELLAR_ENCODER"; - - bytes32 public constant CONTRACT_DIVIDENDS_POOL = "CONTRACT_DIVIDENDS_POOL"; - - bytes32 public constant CONTRACT_TOKEN_USE = "CONTRACT_TOKEN_USE"; - - bytes32 public constant CONTRACT_REVENUE_POOL = "CONTRACT_REVENUE_POOL"; - - bytes32 public constant CONTRACT_ERC721_BRIDGE = "CONTRACT_ERC721_BRIDGE"; - - bytes32 public constant CONTRACT_PET_BASE = "CONTRACT_PET_BASE"; - - // Cut owner takes on each auction, measured in basis points (1/100 of a percent). - // this can be considered as transaction fee. - // Values 0-10,000 map to 0%-100% - // set ownerCut to 4% - // ownerCut = 400; - bytes32 public constant UINT_AUCTION_CUT = "UINT_AUCTION_CUT"; // Denominator is 10000 - - bytes32 public constant UINT_TOKEN_OFFER_CUT = "UINT_TOKEN_OFFER_CUT"; // Denominator is 10000 - - // Cut referer takes on each auction, measured in basis points (1/100 of a percent). - // which cut from transaction fee. - // Values 0-10,000 map to 0%-100% - // set refererCut to 4% - // refererCut = 400; - bytes32 public constant UINT_REFERER_CUT = "UINT_REFERER_CUT"; - - bytes32 public constant CONTRACT_LAND_RESOURCE = "CONTRACT_LAND_RESOURCE"; -} - -// Root file: contracts/LandSettingIds.sol - -pragma solidity ^0.4.24; - -// import "@evolutionland/common/contracts/SettingIds.sol"; - -contract LandSettingIds is SettingIds { - -} \ No newline at end of file diff --git a/flat/Migrations.sol b/flat/Migrations.sol deleted file mode 100644 index 417a486..0000000 --- a/flat/Migrations.sol +++ /dev/null @@ -1,572 +0,0 @@ -// Dependency file: @evolutionland/common/contracts/interfaces/ERC223ReceivingContract.sol - -// pragma solidity ^0.4.23; - - /* - * Contract that is working with ERC223 tokens - * https://github.com/ethereum/EIPs/issues/223 - */ - -/// @title ERC223ReceivingContract - Standard contract implementation for compatibility with ERC223 tokens. -contract ERC223ReceivingContract { - - /// @dev Function that is called when a user or another contract wants to transfer funds. - /// @param _from Transaction initiator, analogue of msg.sender - /// @param _value Number of tokens to transfer. - /// @param _data Data containig a function signature and/or parameters - function tokenFallback(address _from, uint256 _value, bytes _data) public; - -} - - -// Dependency file: @evolutionland/common/contracts/interfaces/TokenController.sol - -// pragma solidity ^0.4.23; - - -/// @dev The token controller contract must implement these functions -contract TokenController { - /// @notice Called when `_owner` sends ether to the MiniMe Token contract - /// @param _owner The address that sent the ether to create tokens - /// @return True if the ether is accepted, false if it throws - function proxyPayment(address _owner, bytes4 sig, bytes data) payable public returns (bool); - - /// @notice Notifies the controller about a token transfer allowing the - /// controller to react if desired - /// @param _from The origin of the transfer - /// @param _to The destination of the transfer - /// @param _amount The amount of the transfer - /// @return False if the controller does not authorize the transfer - function onTransfer(address _from, address _to, uint _amount) public returns (bool); - - /// @notice Notifies the controller about an approval allowing the - /// controller to react if desired - /// @param _owner The address that calls `approve()` - /// @param _spender The spender in the `approve()` call - /// @param _amount The amount in the `approve()` call - /// @return False if the controller does not authorize the approval - function onApprove(address _owner, address _spender, uint _amount) public returns (bool); -} - - -// Dependency file: @evolutionland/common/contracts/interfaces/ApproveAndCallFallBack.sol - -// pragma solidity ^0.4.23; - -contract ApproveAndCallFallBack { - function receiveApproval(address from, uint256 _amount, address _token, bytes _data) public; -} - -// Dependency file: @evolutionland/common/contracts/interfaces/ERC223.sol - -// pragma solidity ^0.4.23; - -contract ERC223 { - function transfer(address to, uint amount, bytes data) public returns (bool ok); - - function transferFrom(address from, address to, uint256 amount, bytes data) public returns (bool ok); - - event ERC223Transfer(address indexed from, address indexed to, uint amount, bytes data); -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol - -// pragma solidity ^0.4.24; - - -/** - * @title ERC20Basic - * @dev Simpler version of ERC20 interface - * See https://github.com/ethereum/EIPs/issues/179 - */ -contract ERC20Basic { - function totalSupply() public view returns (uint256); - function balanceOf(address _who) public view returns (uint256); - function transfer(address _to, uint256 _value) public returns (bool); - event Transfer(address indexed from, address indexed to, uint256 value); -} - - -// Dependency file: openzeppelin-solidity/contracts/token/ERC20/ERC20.sol - -// pragma solidity ^0.4.24; - -// import "openzeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol"; - - -/** - * @title ERC20 interface - * @dev see https://github.com/ethereum/EIPs/issues/20 - */ -contract ERC20 is ERC20Basic { - function allowance(address _owner, address _spender) - public view 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 - ); -} - - -// Dependency file: openzeppelin-solidity/contracts/math/SafeMath.sol - -// pragma solidity ^0.4.24; - - -/** - * @title SafeMath - * @dev Math operations with safety checks that throw on error - */ -library SafeMath { - - /** - * @dev Multiplies two numbers, throws on overflow. - */ - function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) { - // Gas optimization: this is cheaper than asserting 'a' not being zero, but the - // benefit is lost if 'b' is also tested. - // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 - if (_a == 0) { - return 0; - } - - c = _a * _b; - assert(c / _a == _b); - return c; - } - - /** - * @dev Integer division of two numbers, truncating the quotient. - */ - function div(uint256 _a, uint256 _b) internal pure returns (uint256) { - // assert(_b > 0); // Solidity automatically throws when dividing by 0 - // uint256 c = _a / _b; - // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold - return _a / _b; - } - - /** - * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). - */ - function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { - assert(_b <= _a); - return _a - _b; - } - - /** - * @dev Adds two numbers, throws on overflow. - */ - function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) { - c = _a + _b; - assert(c >= _a); - return c; - } -} - - -// Dependency file: @evolutionland/common/contracts/StandardERC20Base.sol - -// pragma solidity ^0.4.23; - -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol'; -// import "openzeppelin-solidity/contracts/math/SafeMath.sol"; - -contract StandardERC20Base is ERC20 { - using SafeMath for uint256; - - uint256 _supply; - mapping (address => uint256) _balances; - mapping (address => mapping (address => uint256)) _approvals; - - function totalSupply() public view returns (uint) { - return _supply; - } - function balanceOf(address src) public view returns (uint) { - return _balances[src]; - } - function allowance(address src, address guy) public view returns (uint) { - return _approvals[src][guy]; - } - - function transfer(address dst, uint wad) public returns (bool) { - return transferFrom(msg.sender, dst, wad); - } - - function transferFrom(address src, address dst, uint wad) - public - returns (bool) - { - if (src != msg.sender) { - _approvals[src][msg.sender] = _approvals[src][msg.sender].sub(wad); - } - - _balances[src] = _balances[src].sub(wad); - _balances[dst] = _balances[dst].add(wad); - - emit Transfer(src, dst, wad); - - return true; - } - - function approve(address guy, uint wad) public returns (bool) { - _approvals[msg.sender][guy] = wad; - - emit Approval(msg.sender, guy, wad); - - return true; - } -} - - -// Dependency file: @evolutionland/common/contracts/interfaces/IAuthority.sol - -// pragma solidity ^0.4.24; - -contract IAuthority { - function canCall( - address src, address dst, bytes4 sig - ) public view returns (bool); -} - -// Dependency file: @evolutionland/common/contracts/DSAuth.sol - -// pragma solidity ^0.4.24; - -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/IAuthority.sol'; - -contract DSAuthEvents { - event LogSetAuthority (address indexed authority); - event LogSetOwner (address indexed owner); -} - -/** - * @title DSAuth - * @dev The DSAuth contract is reference implement of https://github.com/dapphub/ds-auth - * But in the isAuthorized method, the src from address(this) is remove for safty concern. - */ -contract DSAuth is DSAuthEvents { - IAuthority public authority; - address public owner; - - constructor() public { - owner = msg.sender; - emit LogSetOwner(msg.sender); - } - - function setOwner(address owner_) - public - auth - { - owner = owner_; - emit LogSetOwner(owner); - } - - function setAuthority(IAuthority authority_) - public - auth - { - authority = authority_; - emit LogSetAuthority(authority); - } - - modifier auth { - require(isAuthorized(msg.sender, msg.sig)); - _; - } - - modifier onlyOwner() { - require(msg.sender == owner); - _; - } - - function isAuthorized(address src, bytes4 sig) internal view returns (bool) { - if (src == owner) { - return true; - } else if (authority == IAuthority(0)) { - return false; - } else { - return authority.canCall(src, this, sig); - } - } -} - - -// Dependency file: @evolutionland/common/contracts/StandardERC223.sol - -// pragma solidity ^0.4.24; - -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/ERC223ReceivingContract.sol'; -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/TokenController.sol'; -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/ApproveAndCallFallBack.sol'; -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/ERC223.sol'; -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/StandardERC20Base.sol'; -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/DSAuth.sol'; - -// This is a contract for demo and test. -contract StandardERC223 is StandardERC20Base, DSAuth, ERC223 { - event Burn(address indexed burner, uint256 value); - event Mint(address indexed to, uint256 amount); - - bytes32 public symbol; - uint256 public decimals = 18; // standard token precision. override to customize - // Optional token name - bytes32 public name = ""; - - address public controller; - - constructor(bytes32 _symbol) public { - symbol = _symbol; - controller = msg.sender; - } - - function setName(bytes32 name_) public auth { - name = name_; - } - -////////// -// Controller Methods -////////// - /// @notice Changes the controller of the contract - /// @param _newController The new controller of the contract - function changeController(address _newController) public auth { - controller = _newController; - } - - /// @notice Send `_amount` tokens to `_to` from `_from` on the condition it - /// is approved by `_from` - /// @param _from The address holding the tokens being transferred - /// @param _to The address of the recipient - /// @param _amount The amount of tokens to be transferred - /// @return True if the transfer was successful - function transferFrom(address _from, address _to, uint256 _amount - ) public returns (bool success) { - // Alerts the token controller of the transfer - if (isContract(controller)) { - if (!TokenController(controller).onTransfer(_from, _to, _amount)) - revert(); - } - - success = super.transferFrom(_from, _to, _amount); - } - - /* - * ERC 223 - * Added support for the ERC 223 "tokenFallback" method in a "transfer" function with a payload. - */ - function transferFrom(address _from, address _to, uint256 _amount, bytes _data) - public - returns (bool success) - { - // Alerts the token controller of the transfer - if (isContract(controller)) { - if (!TokenController(controller).onTransfer(_from, _to, _amount)) - revert(); - } - - require(super.transferFrom(_from, _to, _amount)); - - if (isContract(_to)) { - ERC223ReceivingContract receiver = ERC223ReceivingContract(_to); - receiver.tokenFallback(_from, _amount, _data); - } - - emit ERC223Transfer(_from, _to, _amount, _data); - - return true; - } - - function issue(address _to, uint256 _amount) public auth { - mint(_to, _amount); - } - - function destroy(address _from, uint256 _amount) public auth { - burn(_from, _amount); - } - - function mint(address _to, uint _amount) public auth { - _supply = _supply.add(_amount); - _balances[_to] = _balances[_to].add(_amount); - emit Mint(_to, _amount); - emit Transfer(address(0), _to, _amount); - } - - function burn(address _who, uint _value) public auth { - require(_value <= _balances[_who]); - // no need to require value <= totalSupply, since that would imply the - // sender's balance is greater than the totalSupply, which *should* be an assertion failure - - _balances[_who] = _balances[_who].sub(_value); - _supply = _supply.sub(_value); - emit Burn(_who, _value); - emit Transfer(_who, address(0), _value); - } - - /* - * ERC 223 - * Added support for the ERC 223 "tokenFallback" method in a "transfer" function with a payload. - * https://github.com/ethereum/EIPs/issues/223 - * function transfer(address _to, uint256 _value, bytes _data) public returns (bool success); - */ - /// @notice Send `_value` tokens to `_to` from `msg.sender` and trigger - /// tokenFallback if sender is a contract. - /// @dev Function that is called when a user or another contract wants to transfer funds. - /// @param _to Address of token receiver. - /// @param _amount Number of tokens to transfer. - /// @param _data Data to be sent to tokenFallback - /// @return Returns success of function call. - function transfer( - address _to, - uint256 _amount, - bytes _data) - public - returns (bool success) - { - return transferFrom(msg.sender, _to, _amount, _data); - } - - /// @notice `msg.sender` approves `_spender` to spend `_amount` tokens on - /// its behalf. This is a modified version of the ERC20 approve function - /// to be a little bit safer - /// @param _spender The address of the account able to transfer the tokens - /// @param _amount The amount of tokens to be approved for transfer - /// @return True if the approval was successful - function approve(address _spender, uint256 _amount) public returns (bool success) { - // Alerts the token controller of the approve function call - if (isContract(controller)) { - if (!TokenController(controller).onApprove(msg.sender, _spender, _amount)) - revert(); - } - - return super.approve(_spender, _amount); - } - - /// @notice `msg.sender` approves `_spender` to send `_amount` tokens on - /// its behalf, and then a function is triggered in the contract that is - /// being approved, `_spender`. This allows users to use their tokens to - /// interact with contracts in one function call instead of two - /// @param _spender The address of the contract able to transfer the tokens - /// @param _amount The amount of tokens to be approved for transfer - /// @return True if the function call was successful - function approveAndCall(address _spender, uint256 _amount, bytes _extraData - ) public returns (bool success) { - if (!approve(_spender, _amount)) revert(); - - ApproveAndCallFallBack(_spender).receiveApproval( - msg.sender, - _amount, - this, - _extraData - ); - - return true; - } - - /// @dev Internal function to determine if an address is a contract - /// @param _addr The address being queried - /// @return True if `_addr` is a contract - function isContract(address _addr) constant internal returns(bool) { - uint size; - if (_addr == 0) return false; - assembly { - size := extcodesize(_addr) - } - return size>0; - } - - /// @notice The fallback function: If the contract's controller has not been - /// set to 0, then the `proxyPayment` method is called which relays the - /// ether and creates tokens as described in the token controller contract - function () public payable { - if (isContract(controller)) { - if (! TokenController(controller).proxyPayment.value(msg.value)(msg.sender, msg.sig, msg.data)) - revert(); - } else { - revert(); - } - } - -////////// -// Safety Methods -////////// - - /// @notice This method can be used by the owner to extract mistakenly - /// sent tokens to this contract. - /// @param _token The address of the token contract that you want to recover - /// set to 0 in case you want to extract ether. - function claimTokens(address _token) public auth { - if (_token == 0x0) { - address(msg.sender).transfer(address(this).balance); - return; - } - - ERC20 token = ERC20(_token); - uint balance = token.balanceOf(this); - token.transfer(address(msg.sender), balance); - - emit ClaimedTokens(_token, address(msg.sender), balance); - } - -//////////////// -// Events -//////////////// - - event ClaimedTokens(address indexed _token, address indexed _controller, uint _amount); -} - -// Dependency file: @evolutionland/common/contracts/MintAndBurnAuthority.sol - -// pragma solidity ^0.4.24; - -contract MintAndBurnAuthority { - - mapping (address => bool) public whiteList; - - constructor(address[] _whitelists) public { - for (uint i = 0; i < _whitelists.length; i ++) { - whiteList[_whitelists[i]] = true; - } - } - - function canCall( - address _src, address _dst, bytes4 _sig - ) public view returns (bool) { - return ( whiteList[_src] && _sig == bytes4(keccak256("mint(address,uint256)")) ) || - ( whiteList[_src] && _sig == bytes4(keccak256("burn(address,uint256)")) ); - } -} - - -// Root file: contracts/Migrations.sol - -pragma solidity ^0.4.24; - -// import "@evolutionland/common/contracts/StandardERC223.sol"; -// import "@evolutionland/common/contracts/MintAndBurnAuthority.sol"; -contract Migrations { - address public owner; - uint public last_completed_migration; - - constructor() public { - owner = msg.sender; - } - - modifier restricted() { - if (msg.sender == owner) _; - } - - function setCompleted(uint completed) public restricted { - last_completed_migration = completed; - } - - function upgrade(address new_address) public restricted { - Migrations upgraded = Migrations(new_address); - upgraded.setCompleted(last_completed_migration); - } -} diff --git a/flat/MysteriousTreasure.sol b/flat/MysteriousTreasure.sol deleted file mode 100644 index 6229f20..0000000 --- a/flat/MysteriousTreasure.sol +++ /dev/null @@ -1,440 +0,0 @@ -// Dependency file: openzeppelin-solidity/contracts/math/SafeMath.sol - -// pragma solidity ^0.4.24; - - -/** - * @title SafeMath - * @dev Math operations with safety checks that throw on error - */ -library SafeMath { - - /** - * @dev Multiplies two numbers, throws on overflow. - */ - function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) { - // Gas optimization: this is cheaper than asserting 'a' not being zero, but the - // benefit is lost if 'b' is also tested. - // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 - if (_a == 0) { - return 0; - } - - c = _a * _b; - assert(c / _a == _b); - return c; - } - - /** - * @dev Integer division of two numbers, truncating the quotient. - */ - function div(uint256 _a, uint256 _b) internal pure returns (uint256) { - // assert(_b > 0); // Solidity automatically throws when dividing by 0 - // uint256 c = _a / _b; - // assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold - return _a / _b; - } - - /** - * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend). - */ - function sub(uint256 _a, uint256 _b) internal pure returns (uint256) { - assert(_b <= _a); - return _a - _b; - } - - /** - * @dev Adds two numbers, throws on overflow. - */ - function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) { - c = _a + _b; - assert(c >= _a); - return c; - } -} - - -// Dependency file: @evolutionland/common/contracts/interfaces/ISettingsRegistry.sol - -// pragma solidity ^0.4.24; - -contract ISettingsRegistry { - enum SettingsValueTypes { NONE, UINT, STRING, ADDRESS, BYTES, BOOL, INT } - - function uintOf(bytes32 _propertyName) public view returns (uint256); - - function stringOf(bytes32 _propertyName) public view returns (string); - - function addressOf(bytes32 _propertyName) public view returns (address); - - function bytesOf(bytes32 _propertyName) public view returns (bytes); - - function boolOf(bytes32 _propertyName) public view returns (bool); - - function intOf(bytes32 _propertyName) public view returns (int); - - function setUintProperty(bytes32 _propertyName, uint _value) public; - - function setStringProperty(bytes32 _propertyName, string _value) public; - - function setAddressProperty(bytes32 _propertyName, address _value) public; - - function setBytesProperty(bytes32 _propertyName, bytes _value) public; - - function setBoolProperty(bytes32 _propertyName, bool _value) public; - - function setIntProperty(bytes32 _propertyName, int _value) public; - - function getValueTypeOf(bytes32 _propertyName) public view returns (uint /* SettingsValueTypes */ ); - - event ChangeProperty(bytes32 indexed _propertyName, uint256 _type); -} - -// Dependency file: @evolutionland/common/contracts/interfaces/IAuthority.sol - -// pragma solidity ^0.4.24; - -contract IAuthority { - function canCall( - address src, address dst, bytes4 sig - ) public view returns (bool); -} - -// Dependency file: @evolutionland/common/contracts/DSAuth.sol - -// pragma solidity ^0.4.24; - -// import '/Users/echo/workspace/contract/evolutionlandorg/land/node_modules/@evolutionland/common/contracts/interfaces/IAuthority.sol'; - -contract DSAuthEvents { - event LogSetAuthority (address indexed authority); - event LogSetOwner (address indexed owner); -} - -/** - * @title DSAuth - * @dev The DSAuth contract is reference implement of https://github.com/dapphub/ds-auth - * But in the isAuthorized method, the src from address(this) is remove for safty concern. - */ -contract DSAuth is DSAuthEvents { - IAuthority public authority; - address public owner; - - constructor() public { - owner = msg.sender; - emit LogSetOwner(msg.sender); - } - - function setOwner(address owner_) - public - auth - { - owner = owner_; - emit LogSetOwner(owner); - } - - function setAuthority(IAuthority authority_) - public - auth - { - authority = authority_; - emit LogSetAuthority(authority); - } - - modifier auth { - require(isAuthorized(msg.sender, msg.sig)); - _; - } - - modifier onlyOwner() { - require(msg.sender == owner); - _; - } - - function isAuthorized(address src, bytes4 sig) internal view returns (bool) { - if (src == owner) { - return true; - } else if (authority == IAuthority(0)) { - return false; - } else { - return authority.canCall(src, this, sig); - } - } -} - - -// Dependency file: @evolutionland/common/contracts/SettingIds.sol - -// pragma solidity ^0.4.24; - -/** - Id definitions for SettingsRegistry.sol - Can be used in conjunction with the settings registry to get properties -*/ -contract SettingIds { - bytes32 public constant CONTRACT_RING_ERC20_TOKEN = "CONTRACT_RING_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_KTON_ERC20_TOKEN = "CONTRACT_KTON_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_GOLD_ERC20_TOKEN = "CONTRACT_GOLD_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_WOOD_ERC20_TOKEN = "CONTRACT_WOOD_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_WATER_ERC20_TOKEN = "CONTRACT_WATER_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_FIRE_ERC20_TOKEN = "CONTRACT_FIRE_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_SOIL_ERC20_TOKEN = "CONTRACT_SOIL_ERC20_TOKEN"; - - bytes32 public constant CONTRACT_OBJECT_OWNERSHIP = "CONTRACT_OBJECT_OWNERSHIP"; - - bytes32 public constant CONTRACT_TOKEN_LOCATION = "CONTRACT_TOKEN_LOCATION"; - - bytes32 public constant CONTRACT_LAND_BASE = "CONTRACT_LAND_BASE"; - - bytes32 public constant CONTRACT_USER_POINTS = "CONTRACT_USER_POINTS"; - - bytes32 public constant CONTRACT_INTERSTELLAR_ENCODER = "CONTRACT_INTERSTELLAR_ENCODER"; - - bytes32 public constant CONTRACT_DIVIDENDS_POOL = "CONTRACT_DIVIDENDS_POOL"; - - bytes32 public constant CONTRACT_TOKEN_USE = "CONTRACT_TOKEN_USE"; - - bytes32 public constant CONTRACT_REVENUE_POOL = "CONTRACT_REVENUE_POOL"; - - bytes32 public constant CONTRACT_ERC721_BRIDGE = "CONTRACT_ERC721_BRIDGE"; - - bytes32 public constant CONTRACT_PET_BASE = "CONTRACT_PET_BASE"; - - // Cut owner takes on each auction, measured in basis points (1/100 of a percent). - // this can be considered as transaction fee. - // Values 0-10,000 map to 0%-100% - // set ownerCut to 4% - // ownerCut = 400; - bytes32 public constant UINT_AUCTION_CUT = "UINT_AUCTION_CUT"; // Denominator is 10000 - - bytes32 public constant UINT_TOKEN_OFFER_CUT = "UINT_TOKEN_OFFER_CUT"; // Denominator is 10000 - - // Cut referer takes on each auction, measured in basis points (1/100 of a percent). - // which cut from transaction fee. - // Values 0-10,000 map to 0%-100% - // set refererCut to 4% - // refererCut = 400; - bytes32 public constant UINT_REFERER_CUT = "UINT_REFERER_CUT"; - - bytes32 public constant CONTRACT_LAND_RESOURCE = "CONTRACT_LAND_RESOURCE"; -} - -// Dependency file: contracts/interfaces/ILandBase.sol - -// pragma solidity ^0.4.24; - -contract ILandBase { - - /* - * Event - */ - event ModifiedResourceRate(uint indexed tokenId, address resourceToken, uint16 newResourceRate); - event HasboxSetted(uint indexed tokenId, bool hasBox); - - event ChangedReourceRateAttr(uint indexed tokenId, uint256 attr); - - event ChangedFlagMask(uint indexed tokenId, uint256 newFlagMask); - - event CreatedNewLand(uint indexed tokenId, int x, int y, address beneficiary, uint256 resourceRateAttr, uint256 mask); - - function defineResouceTokenRateAttrId(address _resourceToken, uint8 _attrId) public; - - function setHasBox(uint _landTokenID, bool isHasBox) public; - function isReserved(uint256 _tokenId) public view returns (bool); - function isSpecial(uint256 _tokenId) public view returns (bool); - function isHasBox(uint256 _tokenId) public view returns (bool); - - function getResourceRateAttr(uint _landTokenId) public view returns (uint256); - function setResourceRateAttr(uint _landTokenId, uint256 _newResourceRateAttr) public; - - function getResourceRate(uint _landTokenId, address _resouceToken) public view returns (uint16); - function setResourceRate(uint _landTokenID, address _resourceToken, uint16 _newResouceRate) public; - - function getFlagMask(uint _landTokenId) public view returns (uint256); - - function setFlagMask(uint _landTokenId, uint256 _newFlagMask) public; - - function resourceToken2RateAttrId(address _resourceToken) external view returns (uint256); -} - - -// Dependency file: contracts/interfaces/IMysteriousTreasure.sol - -// pragma solidity ^0.4.24; - -contract IMysteriousTreasure { - - function unbox(uint256 _tokenId) public returns (uint, uint, uint, uint, uint); - -} - -// Root file: contracts/MysteriousTreasure.sol - -pragma solidity ^0.4.23; - -// import "openzeppelin-solidity/contracts/math/SafeMath.sol"; -// import "@evolutionland/common/contracts/interfaces/ISettingsRegistry.sol"; -// import "@evolutionland/common/contracts/DSAuth.sol"; -// import "@evolutionland/common/contracts/SettingIds.sol"; -// import "contracts/interfaces/ILandBase.sol"; -// import "contracts/interfaces/IMysteriousTreasure.sol"; - -contract MysteriousTreasure is DSAuth, SettingIds, IMysteriousTreasure { - using SafeMath for *; - - bool private singletonLock = false; - - ISettingsRegistry public registry; - - // the key of resourcePool are 0,1,2,3,4 - // respectively refer to gold,wood,water,fire,soil - mapping (uint256 => uint256) public resourcePool; - - // number of box left - uint public totalBoxNotOpened; - - // event unbox - event Unbox(uint indexed tokenId, uint goldRate, uint woodRate, uint waterRate, uint fireRate, uint soilRate); - - /* - * Modifiers - */ - modifier singletonLockCall() { - require(!singletonLock, "Only can call once"); - _; - singletonLock = true; - } - - // this need to be created in ClockAuction cotnract - constructor() public { - - // initializeContract - } - - function initializeContract(ISettingsRegistry _registry, uint256[5] _resources) public singletonLockCall { - owner = msg.sender; - - registry = _registry; - - totalBoxNotOpened = 176; - for(uint i = 0; i < 5; i++) { - _setResourcePool(i, _resources[i]); - } - } - - //TODO: consider authority again - // this is invoked in auction.claimLandAsset - function unbox(uint256 _tokenId) - public - auth - returns (uint, uint, uint, uint, uint) { - ILandBase landBase = ILandBase(registry.addressOf(SettingIds.CONTRACT_LAND_BASE)); - if(! landBase.isHasBox(_tokenId) ) { - return (0,0,0,0,0); - } - - // after unboxing, set hasBox(tokenId) to false to restrict unboxing - // set hasBox to false before unboxing operations for safety reason - landBase.setHasBox(_tokenId, false); - - uint16[5] memory resourcesReward; - (resourcesReward[0], resourcesReward[1], - resourcesReward[2], resourcesReward[3], resourcesReward[4]) = _computeAndExtractRewardFromPool(); - - address resouceToken = registry.addressOf(SettingIds.CONTRACT_GOLD_ERC20_TOKEN); - landBase.setResourceRate(_tokenId, resouceToken, landBase.getResourceRate(_tokenId, resouceToken) + resourcesReward[0]); - - resouceToken = registry.addressOf(SettingIds.CONTRACT_WOOD_ERC20_TOKEN); - landBase.setResourceRate(_tokenId, resouceToken, landBase.getResourceRate(_tokenId, resouceToken) + resourcesReward[1]); - - resouceToken = registry.addressOf(SettingIds.CONTRACT_WATER_ERC20_TOKEN); - landBase.setResourceRate(_tokenId, resouceToken, landBase.getResourceRate(_tokenId, resouceToken) + resourcesReward[2]); - - resouceToken = registry.addressOf(SettingIds.CONTRACT_FIRE_ERC20_TOKEN); - landBase.setResourceRate(_tokenId, resouceToken, landBase.getResourceRate(_tokenId, resouceToken) + resourcesReward[3]); - - resouceToken = registry.addressOf(SettingIds.CONTRACT_SOIL_ERC20_TOKEN); - landBase.setResourceRate(_tokenId, resouceToken, landBase.getResourceRate(_tokenId, resouceToken) + resourcesReward[4]); - - // only record increment of resources - emit Unbox(_tokenId, resourcesReward[0], resourcesReward[1], resourcesReward[2], resourcesReward[3], resourcesReward[4]); - - return (resourcesReward[0], resourcesReward[1], resourcesReward[2], resourcesReward[3], resourcesReward[4]); - } - - // rewards ranges from [0, 2 * average_of_resourcePool_left] - // if early players get high resourceReward, then the later ones will get lower. - // in other words, if early players get low resourceReward, the later ones get higher. - // think about snatching wechat's virtual red envelopes in groups. - function _computeAndExtractRewardFromPool() internal returns(uint16,uint16,uint16,uint16,uint16) { - if ( totalBoxNotOpened == 0 ) { - return (0,0,0,0,0); - } - - uint16[5] memory resourceRewards; - - // from fomo3d - // msg.sender is always address(auction), - // so change msg.sender to tx.origin - uint256 seed = uint256(keccak256(abi.encodePacked( - (block.timestamp).add - (block.difficulty).add - ((uint256(keccak256(abi.encodePacked(block.coinbase)))) / (now)).add - (block.gaslimit).add - ((uint256(keccak256(abi.encodePacked(tx.origin)))) / (now)).add - (block.number) - ))); - - for(uint i = 0; i < 5; i++) { - if (totalBoxNotOpened > 1) { - // recources in resourcePool is set by owner - // nad totalBoxNotOpened is set by rules - // there is no need to consider overflow - // goldReward, woodReward, waterReward, fireReward, soilReward - // 2 ** 16 - 1 - uint doubleAverage = (2 * resourcePool[i] / totalBoxNotOpened); - if (doubleAverage > 65535) { - doubleAverage = 65535; - } - - uint resourceReward = seed % doubleAverage; - - resourceRewards[i] = uint16(resourceReward); - - // update resourcePool - _setResourcePool(i, resourcePool[i] - resourceRewards[i]); - } - - if(totalBoxNotOpened == 1) { - resourceRewards[i] = uint16(resourcePool[i]); - _setResourcePool(i, resourcePool[i] - uint256(resourceRewards[i])); - } - } - - totalBoxNotOpened--; - - return (resourceRewards[0],resourceRewards[1], resourceRewards[2], resourceRewards[3], resourceRewards[4]); - - } - - - function _setResourcePool(uint _keyNumber, uint _resources) internal { - require(_keyNumber >= 0 && _keyNumber < 5); - resourcePool[_keyNumber] = _resources; - } - - function setResourcePool(uint _keyNumber, uint _resources) public auth { - _setResourcePool(_keyNumber, _resources); - } - - function setTotalBoxNotOpened(uint _totalBox) public auth { - totalBoxNotOpened = _totalBox; - } - -} diff --git a/flat/MysteriousTreasureAuthority.sol b/flat/MysteriousTreasureAuthority.sol deleted file mode 100644 index 0d5d591..0000000 --- a/flat/MysteriousTreasureAuthority.sol +++ /dev/null @@ -1,20 +0,0 @@ -// Root file: contracts/MysteriousTreasureAuthority.sol - -pragma solidity ^0.4.24; - -contract MysteriousTreasureAuthority { - - constructor(address[] _whitelists) public { - for (uint i = 0; i < _whitelists.length; i ++) { - whiteList[_whitelists[i]] = true; - } - } - - mapping (address => bool) public whiteList; - - function canCall( - address _src, address _dst, bytes4 _sig - ) public view returns (bool) { - return whiteList[_src]; - } -} \ No newline at end of file From d18808241bd6d666e982a14edbdfd30698c5ef34 Mon Sep 17 00:00:00 2001 From: echo Date: Thu, 22 Apr 2021 20:58:10 +0800 Subject: [PATCH 03/32] dapp compatible --- .env | 7 +++++++ Makefile | 1 + 2 files changed, 8 insertions(+) create mode 100644 .env create mode 100644 Makefile diff --git a/.env b/.env new file mode 100644 index 0000000..8403628 --- /dev/null +++ b/.env @@ -0,0 +1,7 @@ +export DAPP_SRC=contracts +export DAPP_LIB=lib +export DAPP_REMAPPINGS="openzeppelin-solidity/=lib/zeppelin-solidity/ +@evolutionland/common/=lib/common-contracts/ +@evolutionland/upgraeability-using-unstructured-storage/=lib/upgradeability-using-unstructured-storage/" +export DAPP_BUILD_OPTIMIZE=1 +unset SOLC_FLAGS DAPP_BUILD_LEGACY DAPP_BUILD_EXTRACT diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8b2a92c --- /dev/null +++ b/Makefile @@ -0,0 +1 @@ +all :; source .env && dapp --use solc:0.4.24 build From ae19feb37cae21c92c0ada35960fec86e272b54d Mon Sep 17 00:00:00 2001 From: echo Date: Thu, 22 Apr 2021 20:58:23 +0800 Subject: [PATCH 04/32] dapp install evolutionlandorg/upgradeability-using-unstructured-storage --- .gitmodules | 3 +++ lib/upgradeability-using-unstructured-storage | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 lib/upgradeability-using-unstructured-storage diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..7846f0c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/upgradeability-using-unstructured-storage"] + path = lib/upgradeability-using-unstructured-storage + url = https://github.com/evolutionlandorg/upgradeability-using-unstructured-storage diff --git a/lib/upgradeability-using-unstructured-storage b/lib/upgradeability-using-unstructured-storage new file mode 160000 index 0000000..5d89ae1 --- /dev/null +++ b/lib/upgradeability-using-unstructured-storage @@ -0,0 +1 @@ +Subproject commit 5d89ae1a00943cbe06d2fb97ad8ade0f9a7f8f08 From 3b244f6c7c305fd714e70fb80bf7233a76111771 Mon Sep 17 00:00:00 2001 From: echo Date: Thu, 22 Apr 2021 20:58:37 +0800 Subject: [PATCH 05/32] dapp install evolutionlandorg/common-contracts --- .gitmodules | 3 +++ lib/common-contracts | 1 + 2 files changed, 4 insertions(+) create mode 160000 lib/common-contracts diff --git a/.gitmodules b/.gitmodules index 7846f0c..f33fba3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "lib/upgradeability-using-unstructured-storage"] path = lib/upgradeability-using-unstructured-storage url = https://github.com/evolutionlandorg/upgradeability-using-unstructured-storage +[submodule "lib/common-contracts"] + path = lib/common-contracts + url = https://github.com/evolutionlandorg/common-contracts diff --git a/lib/common-contracts b/lib/common-contracts new file mode 160000 index 0000000..2873a4f --- /dev/null +++ b/lib/common-contracts @@ -0,0 +1 @@ +Subproject commit 2873a4f8f970bd442ffcf9c6ae63b3dc79e743db From abbe9514b15bf56993e3a4dafa5ed4dd1eddffed Mon Sep 17 00:00:00 2001 From: echo Date: Thu, 22 Apr 2021 20:58:48 +0800 Subject: [PATCH 06/32] dapp install OpenZeppelin/zeppelin-solidity --- .gitmodules | 3 +++ lib/zeppelin-solidity | 1 + 2 files changed, 4 insertions(+) create mode 160000 lib/zeppelin-solidity diff --git a/.gitmodules b/.gitmodules index f33fba3..35e25c8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "lib/common-contracts"] path = lib/common-contracts url = https://github.com/evolutionlandorg/common-contracts +[submodule "lib/zeppelin-solidity"] + path = lib/zeppelin-solidity + url = https://github.com/OpenZeppelin/zeppelin-solidity diff --git a/lib/zeppelin-solidity b/lib/zeppelin-solidity new file mode 160000 index 0000000..165e6f1 --- /dev/null +++ b/lib/zeppelin-solidity @@ -0,0 +1 @@ +Subproject commit 165e6f19489786c9c6abfcc9bdc8f2815d807935 From 22d4b8cc1c0a8a9d9361f7c159616ba966146a92 Mon Sep 17 00:00:00 2001 From: echo Date: Thu, 22 Apr 2021 20:59:15 +0800 Subject: [PATCH 07/32] dapp compatible --- lib/zeppelin-solidity | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/zeppelin-solidity b/lib/zeppelin-solidity index 165e6f1..0e65947 160000 --- a/lib/zeppelin-solidity +++ b/lib/zeppelin-solidity @@ -1 +1 @@ -Subproject commit 165e6f19489786c9c6abfcc9bdc8f2815d807935 +Subproject commit 0e65947efbffc592cffea8c2ae9d3b8e11659854 From 115f949bfca254f4ff827409ef927de5b2784fa2 Mon Sep 17 00:00:00 2001 From: echo Date: Thu, 22 Apr 2021 21:01:05 +0800 Subject: [PATCH 08/32] dapp compatible --- .gitignore | 1 + contracts/LandBaseV2.sol | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0a25cc5..96f8763 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ package-lock.json truffle.js waffle.json cache +out diff --git a/contracts/LandBaseV2.sol b/contracts/LandBaseV2.sol index 0df9ad0..8117f4f 100644 --- a/contracts/LandBaseV2.sol +++ b/contracts/LandBaseV2.sol @@ -71,7 +71,7 @@ contract LandBaseV2 is DSAuth, ILandBase, SettingIds { /** * @dev Same with constructor, but is used and called by storage proxy as logic contract. */ - function initializeContract(address _registry, int256 _xLow, int256 _xHigh, int256 _yLow, int256 yHigh) public singletonLockCall { + function initializeContract(address _registry, int256 _xLow, int256 _xHigh, int256 _yLow, int256 _yHigh) public singletonLockCall { // Ownable constructor owner = msg.sender; emit LogSetOwner(msg.sender); @@ -85,7 +85,7 @@ contract LandBaseV2 is DSAuth, ILandBase, SettingIds { resourceToken2RateAttrId[registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN)] = 4; resourceToken2RateAttrId[registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN)] = 5; - xLow = _xlow; + xLow = _xLow; xHigh = _xHigh; yLow = _yLow; yHigh = _yHigh; From 3e77d34f47205f4918dc743485978c24a5a81d7d Mon Sep 17 00:00:00 2001 From: echo Date: Fri, 23 Apr 2021 12:26:52 +0800 Subject: [PATCH 09/32] make clean --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8b2a92c..5775c51 100644 --- a/Makefile +++ b/Makefile @@ -1 +1,2 @@ -all :; source .env && dapp --use solc:0.4.24 build +all :; source .env && dapp --use solc:0.4.24 build +clean :; dapp clean From c586b8593c92ed52fd50b05173e7fc319a29be10 Mon Sep 17 00:00:00 2001 From: echo Date: Fri, 23 Apr 2021 20:21:56 +0800 Subject: [PATCH 10/32] fix `https://github.com/ethereum/solidity/issues/1565` --- contracts/LandResourceV5.sol | 5 +++-- contracts/interfaces/ILandBase.sol | 1 - contracts/interfaces/ILandBaseExt.sol | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 contracts/interfaces/ILandBaseExt.sol diff --git a/contracts/LandResourceV5.sol b/contracts/LandResourceV5.sol index a9a8123..5f5fff2 100644 --- a/contracts/LandResourceV5.sol +++ b/contracts/LandResourceV5.sol @@ -11,6 +11,7 @@ import "@evolutionland/common/contracts/interfaces/ITokenUse.sol"; import "@evolutionland/common/contracts/interfaces/IActivity.sol"; import "@evolutionland/common/contracts/interfaces/IMinerObject.sol"; import "./interfaces/ILandBase.sol"; +import "./interfaces/ILandBaseExt.sol"; import "./interfaces/IMetaDataTeller.sol"; contract LandResourceV5 is SupportsInterfaceWithLookup, DSAuth, IActivity { @@ -1267,7 +1268,7 @@ contract LandResourceV5 is SupportsInterfaceWithLookup, DSAuth, IActivity { IMetaDataTeller teller = IMetaDataTeller(registry.addressOf(CONTRACT_METADATA_TELLER)); uint256 resourceId = - ILandBase(registry.addressOf(CONTRACT_LAND_BASE)) + ILandBaseExt(registry.addressOf(CONTRACT_LAND_BASE)) .resourceToken2RateAttrId(_resource); require(resourceId > 0 && resourceId < 6, "Furnace: INVALID_RESOURCE"); require( @@ -1401,7 +1402,7 @@ contract LandResourceV5 is SupportsInterfaceWithLookup, DSAuth, IActivity { IMetaDataTeller teller = IMetaDataTeller(registry.addressOf(CONTRACT_METADATA_TELLER)); uint256 resourceId = - ILandBase(registry.addressOf(CONTRACT_LAND_BASE)) + ILandBaseExt(registry.addressOf(CONTRACT_LAND_BASE)) .resourceToken2RateAttrId(_resource); return teller.getRate(bar.token, bar.id, resourceId); } diff --git a/contracts/interfaces/ILandBase.sol b/contracts/interfaces/ILandBase.sol index 1859686..54459de 100644 --- a/contracts/interfaces/ILandBase.sol +++ b/contracts/interfaces/ILandBase.sol @@ -31,5 +31,4 @@ contract ILandBase { function setFlagMask(uint _landTokenId, uint256 _newFlagMask) public; - function resourceToken2RateAttrId(address _resourceToken) external view returns (uint256); } diff --git a/contracts/interfaces/ILandBaseExt.sol b/contracts/interfaces/ILandBaseExt.sol new file mode 100644 index 0000000..c4c6b20 --- /dev/null +++ b/contracts/interfaces/ILandBaseExt.sol @@ -0,0 +1,5 @@ +pragma solidity ^0.4.24; + +contract ILandBaseExt { + function resourceToken2RateAttrId(address _resourceToken) external view returns (uint256); +} From 8e7e3be82e5ba9fbcf62f98a0da0ff1c21094370 Mon Sep 17 00:00:00 2001 From: echo Date: Fri, 23 Apr 2021 21:49:09 +0800 Subject: [PATCH 11/32] add landrsv6 --- contracts/LandResourceV6.sol | 1424 ++++++++++++++++++++++++++++++++++ 1 file changed, 1424 insertions(+) create mode 100644 contracts/LandResourceV6.sol diff --git a/contracts/LandResourceV6.sol b/contracts/LandResourceV6.sol new file mode 100644 index 0000000..27660fd --- /dev/null +++ b/contracts/LandResourceV6.sol @@ -0,0 +1,1424 @@ +pragma solidity ^0.4.24; + +import "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import "openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; +import "openzeppelin-solidity/contracts/introspection/SupportsInterfaceWithLookup.sol"; +import "@evolutionland/common/contracts/interfaces/IMintableERC20.sol"; +import "@evolutionland/common/contracts/interfaces/ISettingsRegistry.sol"; +import "@evolutionland/common/contracts/DSAuth.sol"; +import "@evolutionland/common/contracts/interfaces/IInterstellarEncoder.sol"; +import "@evolutionland/common/contracts/interfaces/ITokenUse.sol"; +import "@evolutionland/common/contracts/interfaces/IActivity.sol"; +import "@evolutionland/common/contracts/interfaces/IMinerObject.sol"; +import "./interfaces/ILandBase.sol"; +import "./interfaces/ILandBaseExt.sol"; +import "./interfaces/IMetaDataTeller.sol"; + +contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { + using SafeMath for *; + + // For every seconds, the speed will decrease by current speed multiplying (DENOMINATOR_in_seconds - seconds) / DENOMINATOR_in_seconds + // resource will decrease 1/10000 every day. + uint256 public constant DENOMINATOR = 10000; + + uint256 public constant TOTAL_SECONDS = DENOMINATOR * (1 days); + + bool private singletonLock = false; + + ISettingsRegistry public registry; + + uint256 public resourceReleaseStartTime; + + // TODO: move to global settings contract. + uint256 public attenPerDay = 1; + uint256 public recoverAttenPerDay = 20; + + // Struct for recording resouces on land which have already been pinged. + // 金, Evolution Land Gold + // 木, Evolution Land Wood + // 水, Evolution Land Water + // 火, Evolution Land fire + // 土, Evolution Land Silicon + struct ResourceMineState { + mapping(address => uint256) mintedBalance; + mapping(address => uint256[]) miners; + mapping(address => uint256) totalMinerStrength; + uint256 lastUpdateSpeedInSeconds; + uint256 lastDestoryAttenInSeconds; + uint256 industryIndex; + uint128 lastUpdateTime; + uint64 totalMiners; + uint64 maxMiners; + } + + struct MinerStatus { + uint256 landTokenId; + address resource; + uint64 indexInResource; + } + + mapping(uint256 => ResourceMineState) public land2ResourceMineState; + mapping(uint256 => MinerStatus) public miner2Index; + + /* + * Event + */ + + event StartMining( + uint256 minerTokenId, + uint256 landId, + address _resource, + uint256 strength + ); + event StopMining( + uint256 minerTokenId, + uint256 landId, + address _resource, + uint256 strength + ); + event ResourceClaimed( + address owner, + uint256 landTokenId, + uint256 goldBalance, + uint256 woodBalance, + uint256 waterBalance, + uint256 fireBalance, + uint256 soilBalance + ); + event UpdateMiningStrengthWhenStop( + uint256 apostleTokenId, + uint256 landId, + uint256 strength + ); + event UpdateMiningStrengthWhenStart( + uint256 apostleTokenId, + uint256 landId, + uint256 strength + ); + + // v5 add begin + event StartBarMining( + uint256 barIndex, + uint256 landId, + address resource, + uint256 rate + ); + event StopBarMining(uint256 barIndex, uint256 landId, address rate); + event LandResourceClaimed( + address owner, + uint256 landId, + uint256 goldBalance, + uint256 woodBalance, + uint256 waterBalance, + uint256 fireBalance, + uint256 soilBalance + ); + event ItemResourceClaimed( + address owner, + address itemToken, + uint256 itemTokenId, + uint256 goldBalance, + uint256 woodBalance, + uint256 waterBalance, + uint256 fireBalance, + uint256 soilBalance + ); + + // land item bar + event Equip( + uint256 indexed tokenId, + address resource, + uint256 index, + address staker, + address token, + uint256 id + ); + event Divest( + uint256 indexed tokenId, + address resource, + uint256 index, + address staker, + address token, + uint256 id + ); + + // 0x434f4e54524143545f4c414e445f424153450000000000000000000000000000 + bytes32 public constant CONTRACT_LAND_BASE = "CONTRACT_LAND_BASE"; + + // 0x434f4e54524143545f474f4c445f45524332305f544f4b454e00000000000000 + bytes32 public constant CONTRACT_GOLD_ERC20_TOKEN = + "CONTRACT_GOLD_ERC20_TOKEN"; + + // 0x434f4e54524143545f574f4f445f45524332305f544f4b454e00000000000000 + bytes32 public constant CONTRACT_WOOD_ERC20_TOKEN = + "CONTRACT_WOOD_ERC20_TOKEN"; + + // 0x434f4e54524143545f57415445525f45524332305f544f4b454e000000000000 + bytes32 public constant CONTRACT_WATER_ERC20_TOKEN = + "CONTRACT_WATER_ERC20_TOKEN"; + + // 0x434f4e54524143545f464952455f45524332305f544f4b454e00000000000000 + bytes32 public constant CONTRACT_FIRE_ERC20_TOKEN = + "CONTRACT_FIRE_ERC20_TOKEN"; + + // 0x434f4e54524143545f534f494c5f45524332305f544f4b454e00000000000000 + bytes32 public constant CONTRACT_SOIL_ERC20_TOKEN = + "CONTRACT_SOIL_ERC20_TOKEN"; + + // 0x434f4e54524143545f494e5445525354454c4c41525f454e434f444552000000 + bytes32 public constant CONTRACT_INTERSTELLAR_ENCODER = + "CONTRACT_INTERSTELLAR_ENCODER"; + + // 0x434f4e54524143545f4f424a4543545f4f574e45525348495000000000000000 + bytes32 public constant CONTRACT_OBJECT_OWNERSHIP = + "CONTRACT_OBJECT_OWNERSHIP"; + + // 0x434f4e54524143545f544f4b454e5f5553450000000000000000000000000000 + bytes32 public constant CONTRACT_TOKEN_USE = "CONTRACT_TOKEN_USE"; + + //0x4655524e4143455f4954454d5f4d494e455f4645450000000000000000000000 + bytes32 public constant FURNACE_ITEM_MINE_FEE = "FURNACE_ITEM_MINE_FEE"; + + // 0x434f4e54524143545f4d455441444154415f54454c4c45520000000000000000 + bytes32 public constant CONTRACT_METADATA_TELLER = + "CONTRACT_METADATA_TELLER"; + + // 0x55494e545f4954454d4241525f50524f544543545f504552494f440000000000 + bytes32 public constant UINT_ITEMBAR_PROTECT_PERIOD = + "UINT_ITEMBAR_PROTECT_PERIOD"; + + // rate precision + uint128 public constant RATE_PRECISION = 10**8; + + uint256 public maxMiners; + + // (itemTokenAddress => (itemTokenId => (resourceAddress => mined balance))) + mapping(address => mapping(uint256 => mapping(address => uint256))) + public itemMinedBalance; + + // (landTokenId => (resourceAddress => (landBarIndex => itemEnhancedRate))) + mapping(uint256 => mapping(address => mapping(uint256 => uint256))) + public land2BarRate; + + // land bar + struct Bar { + address staker; + address token; + uint256 id; + address resource; + } + + // bar status + struct Status { + address staker; + uint256 tokenId; + uint256 index; + } + + // max land bar amount + uint256 public maxAmount; + // (landTokenId => (landBarIndex => BAR)) + mapping(uint256 => mapping(uint256 => Bar)) public landId2Bars; + // (itemTokenAddress => (itemTokenId => STATUS)) + mapping(address => mapping(uint256 => Status)) public itemId2Status; + // (itemTokenAddress => (itemTokenId => itemProtectPeriod)) + mapping(address => mapping(uint256 => uint256)) public protectPeriod; + // v5 add end + + /* + * Modifiers + */ + modifier singletonLockCall() { + require(!singletonLock, "Only can call once"); + _; + singletonLock = true; + } + + function initializeContract( + address _registry, + uint256 _resourceReleaseStartTime + ) public singletonLockCall { + // Ownable constructor + owner = msg.sender; + emit LogSetOwner(msg.sender); + + registry = ISettingsRegistry(_registry); + + resourceReleaseStartTime = _resourceReleaseStartTime; + + _registerInterface(InterfaceId_IActivity); + + maxMiners = 5; + maxAmount = 5; + } + + // get amount of speed uint at this moment + function _getReleaseSpeedInSeconds(uint256 _tokenId, uint256 _time) + internal + view + returns (uint256 currentSpeed) + { + require(_time >= resourceReleaseStartTime, "Should after release time"); + require( + _time >= land2ResourceMineState[_tokenId].lastUpdateTime, + "Should after release last update time" + ); + + // after 10000 days from start + // the resource release speed decreases to 0 + if (TOTAL_SECONDS < _time - resourceReleaseStartTime) { + return 0; + } + + // max amount of speed unit of _tokenId for now + // suppose that speed_uint = 1 in this function + uint256 availableSpeedInSeconds = + TOTAL_SECONDS.sub(_time - resourceReleaseStartTime); + return availableSpeedInSeconds; + // // time from last update + // uint256 timeBetween = + // _time - land2ResourceMineState[_tokenId].lastUpdateTime; + + // // the recover speed is 20/10000, 20 times. + // // recoveryRate overall from lasUpdateTime til now + amount of speed uint at lastUpdateTime + // uint256 nextSpeedInSeconds = + // land2ResourceMineState[_tokenId].lastUpdateSpeedInSeconds + + // timeBetween * + // recoverAttenPerDay; + // // destroyRate overall from lasUpdateTime til now amount of speed uint at lastUpdateTime + // uint256 destroyedSpeedInSeconds = + // timeBetween * + // land2ResourceMineState[_tokenId].lastDestoryAttenInSeconds; + + // if (nextSpeedInSeconds < destroyedSpeedInSeconds) { + // nextSpeedInSeconds = 0; + // } else { + // nextSpeedInSeconds = nextSpeedInSeconds - destroyedSpeedInSeconds; + // } + + // if (nextSpeedInSeconds > availableSpeedInSeconds) { + // nextSpeedInSeconds = availableSpeedInSeconds; + // } + + // return nextSpeedInSeconds; + } + + function getReleaseSpeed( + uint256 _tokenId, + address _resource, + uint256 _time + ) public view returns (uint256 currentSpeed) { + return + ILandBase(registry.addressOf(CONTRACT_LAND_BASE)) + .getResourceRate(_tokenId, _resource) + .mul(_getReleaseSpeedInSeconds(_tokenId, _time)) + .mul(1 ether) + .div(TOTAL_SECONDS); + } + + function _getMinableBalance( + uint256 _tokenId, + address _resource, + uint256 _currentTime, + uint256 _lastUpdateTime + ) public view returns (uint256 minableBalance) { + uint256 speed_in_current_period = + ILandBase(registry.addressOf(CONTRACT_LAND_BASE)) + .getResourceRate(_tokenId, _resource) + .mul( + _getReleaseSpeedInSeconds( + _tokenId, + ((_currentTime + _lastUpdateTime) / 2) + ) + ) + .mul(1 ether) + .div(1 days) + .div(TOTAL_SECONDS); + + // calculate the area of trapezoid + minableBalance = speed_in_current_period.mul( + _currentTime - _lastUpdateTime + ); + } + + function _getMaxMineBalance( + uint256 _tokenId, + address _resource, + uint256 _currentTime, + uint256 _lastUpdateTime + ) internal view returns (uint256) { + // totalMinerStrength is in wei + return + getTotalMiningStrength(_tokenId, _resource) + .mul(_currentTime - _lastUpdateTime) + .div(1 days); + } + + function setMaxMiners(uint256 _maxMiners) public auth { + require(_maxMiners > maxMiners, "Land: INVALID_MAXMINERS"); + maxMiners = _maxMiners; + } + + function mine(uint256 _landTokenId) public { + _mineAllResource( + _landTokenId, + registry.addressOf(CONTRACT_GOLD_ERC20_TOKEN), + registry.addressOf(CONTRACT_WOOD_ERC20_TOKEN), + registry.addressOf(CONTRACT_WATER_ERC20_TOKEN), + registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN), + registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN) + ); + } + + function _mineAllResource( + uint256 _landTokenId, + address _gold, + address _wood, + address _water, + address _fire, + address _soil + ) internal { + require( + IInterstellarEncoder( + registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER) + ) + .getObjectClass(_landTokenId) == 1, + "Token must be land." + ); + + // v5 remove + // if (land2ResourceMineState[_landTokenId].lastUpdateTime == 0) { + // land2ResourceMineState[_landTokenId].lastUpdateTime = uint128( + // resourceReleaseStartTime + // ); + // land2ResourceMineState[_landTokenId] + // .lastUpdateSpeedInSeconds = TOTAL_SECONDS; + // } + + _mineResource(_landTokenId, _gold); + _mineResource(_landTokenId, _wood); + _mineResource(_landTokenId, _water); + _mineResource(_landTokenId, _fire); + _mineResource(_landTokenId, _soil); + + // v5 remove + // land2ResourceMineState[_landTokenId] + // .lastUpdateSpeedInSeconds = _getReleaseSpeedInSeconds( + // _landTokenId, + // now + // ); + + land2ResourceMineState[_landTokenId].lastUpdateTime = uint128(now); + } + + function _distribution( + uint256 _landId, + address _resource, + uint256 minedBalance, + uint256 barsRate + ) internal returns (uint256) { + uint256 landBalance = + minedBalance.mul(RATE_PRECISION).div(barsRate.add(RATE_PRECISION)); + uint256 barsBalance = minedBalance.sub(landBalance); + for (uint256 i = 0; i < maxAmount; i++) { + (address itemToken, uint256 itemId, address resouce) = + getBarItem(_landId, i); + if (itemToken != address(0) && resouce == _resource) { + uint256 barBalance = + barsBalance.mul(getBarRate(_landId, _resource, i)).div( + barsRate + ); + (barBalance, landBalance) = _payFee(barBalance, landBalance); + itemMinedBalance[itemToken][itemId][ + _resource + ] = getItemMinedBalance(itemToken, itemId, _resource).add( + barBalance + ); + } + } + return landBalance; + } + + function _payFee(uint256 barBalance, uint256 landBalance) + internal + view + returns (uint256, uint256) + { + uint256 fee = + barBalance.mul(registry.uintOf(FURNACE_ITEM_MINE_FEE)).div( + RATE_PRECISION + ); + barBalance = barBalance.sub(fee); + landBalance = landBalance.add(fee); + return (barBalance, landBalance); + } + + function _mineResource(uint256 _landId, address _resource) internal { + // the longest seconds to zero speed. + if (getLandMiningStrength(_landId, _resource) == 0) { + return; + } + uint256 minedBalance = _calculateMinedBalance(_landId, _resource, now); + if (minedBalance == 0) { + return; + } + + uint256 barsRate = getBarsRate(_landId, _resource); + uint256 landBalance = minedBalance; + if (barsRate > 0) { + // V5 yeild distribution + landBalance = _distribution( + _landId, + _resource, + minedBalance, + barsRate + ); + } + land2ResourceMineState[_landId].mintedBalance[ + _resource + ] = getLandMinedBalance(_landId, _resource).add(landBalance); + } + + function _calculateMinedBalance( + uint256 _landTokenId, + address _resourceToken, + uint256 _currentTime + ) internal view returns (uint256) { + uint256 currentTime = _currentTime; + + uint256 minedBalance; + uint256 minableBalance; + if (currentTime > (resourceReleaseStartTime + TOTAL_SECONDS)) { + currentTime = (resourceReleaseStartTime + TOTAL_SECONDS); + } + + uint256 lastUpdateTime = + land2ResourceMineState[_landTokenId].lastUpdateTime; + require(currentTime >= lastUpdateTime); + + if (lastUpdateTime >= (resourceReleaseStartTime + TOTAL_SECONDS)) { + minedBalance = 0; + minableBalance = 0; + } else { + minedBalance = _getMaxMineBalance( + _landTokenId, + _resourceToken, + currentTime, + lastUpdateTime + ); + minableBalance = _getMinableBalance( + _landTokenId, + _resourceToken, + currentTime, + lastUpdateTime + ); + } + + if (minedBalance > minableBalance) { + minedBalance = minableBalance; + } + + return minedBalance; + } + + // v5 remove + // function claimAllResource(uint256 _landTokenId) public { + // require( + // msg.sender == ownership.ownerOf(_landTokenId), + // "Must be the owner of the land" + // ); + + // _mineAllResource(_landTokenId, gold, wood, water, fire, soil); + + // uint256 goldBalance; + // uint256 woodBalance; + // uint256 waterBalance; + // uint256 fireBalance; + // uint256 soilBalance; + + // if (land2ResourceMineState[_landTokenId].mintedBalance[gold] > 0) { + // goldBalance = land2ResourceMineState[_landTokenId].mintedBalance[ + // gold + // ]; + // IMintableERC20(gold).mint(msg.sender, goldBalance); + // land2ResourceMineState[_landTokenId].mintedBalance[gold] = 0; + // } + + // if (land2ResourceMineState[_landTokenId].mintedBalance[wood] > 0) { + // woodBalance = land2ResourceMineState[_landTokenId].mintedBalance[ + // wood + // ]; + // IMintableERC20(wood).mint(msg.sender, woodBalance); + // land2ResourceMineState[_landTokenId].mintedBalance[wood] = 0; + // } + + // if (land2ResourceMineState[_landTokenId].mintedBalance[water] > 0) { + // waterBalance = land2ResourceMineState[_landTokenId].mintedBalance[ + // water + // ]; + // IMintableERC20(water).mint(msg.sender, waterBalance); + // land2ResourceMineState[_landTokenId].mintedBalance[water] = 0; + // } + + // if (land2ResourceMineState[_landTokenId].mintedBalance[fire] > 0) { + // fireBalance = land2ResourceMineState[_landTokenId].mintedBalance[ + // fire + // ]; + // IMintableERC20(fire).mint(msg.sender, fireBalance); + // land2ResourceMineState[_landTokenId].mintedBalance[fire] = 0; + // } + + // if (land2ResourceMineState[_landTokenId].mintedBalance[soil] > 0) { + // soilBalance = land2ResourceMineState[_landTokenId].mintedBalance[ + // soil + // ]; + // IMintableERC20(soil).mint(msg.sender, soilBalance); + // land2ResourceMineState[_landTokenId].mintedBalance[soil] = 0; + // } + + // emit ResourceClaimed( + // msg.sender, + // _landTokenId, + // goldBalance, + // woodBalance, + // waterBalance, + // fireBalance, + // soilBalance + // ); + // } + + // both for own _tokenId or hired one + function startMining( + uint256 _tokenId, + uint256 _landTokenId, + address _resource + ) public { + ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).addActivity( + _tokenId, + msg.sender, + 0 + ); + + // require the permission from land owner; + require( + msg.sender == + ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf( + _landTokenId + ), + "Must be the owner of the land" + ); + + // make sure that _tokenId won't be used repeatedly + require(miner2Index[_tokenId].landTokenId == 0); + + // update status! + mine(_landTokenId); + + uint256 _index = + land2ResourceMineState[_landTokenId].miners[_resource].length; + + land2ResourceMineState[_landTokenId].totalMiners += 1; + + // v5 remove + // if (land2ResourceMineState[_landTokenId].maxMiners == 0) { + // land2ResourceMineState[_landTokenId].maxMiners = 5; + // } + + require( + land2ResourceMineState[_landTokenId].totalMiners <= maxMiners, + "Land: EXCEED_MAXAMOUNT" + ); + + address miner = + IInterstellarEncoder( + registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER) + ) + .getObjectAddress(_tokenId); + uint256 strength = + IMinerObject(miner).strengthOf(_tokenId, _resource, _landTokenId); + + land2ResourceMineState[_landTokenId].miners[_resource].push(_tokenId); + land2ResourceMineState[_landTokenId].totalMinerStrength[ + _resource + ] += strength; + + miner2Index[_tokenId] = MinerStatus({ + landTokenId: _landTokenId, + resource: _resource, + indexInResource: uint64(_index) + }); + + emit StartMining(_tokenId, _landTokenId, _resource, strength); + } + + function batchStartMining( + uint256[] _tokenIds, + uint256[] _landTokenIds, + address[] _resources + ) public { + require( + _tokenIds.length == _landTokenIds.length && + _landTokenIds.length == _resources.length, + "input error" + ); + uint256 length = _tokenIds.length; + + for (uint256 i = 0; i < length; i++) { + startMining(_tokenIds[i], _landTokenIds[i], _resources[i]); + } + } + + function batchClaimLandResource(uint256[] _landTokenIds) public { + uint256 length = _landTokenIds.length; + + for (uint256 i = 0; i < length; i++) { + claimLandResource(_landTokenIds[i]); + } + } + + // Only trigger from Token Activity. + function activityStopped(uint256 _tokenId) public auth { + _stopMining(_tokenId); + } + + function stopMining(uint256 _tokenId) public { + ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).removeActivity( + _tokenId, + msg.sender + ); + } + + function _stopMining(uint256 _tokenId) internal { + // remove the miner from land2ResourceMineState; + uint64 minerIndex = miner2Index[_tokenId].indexInResource; + address resource = miner2Index[_tokenId].resource; + uint256 landTokenId = miner2Index[_tokenId].landTokenId; + + // update status! + mine(landTokenId); + + uint64 lastMinerIndex = + uint64( + land2ResourceMineState[landTokenId].miners[resource].length.sub( + 1 + ) + ); + uint256 lastMiner = + land2ResourceMineState[landTokenId].miners[resource][ + lastMinerIndex + ]; + + land2ResourceMineState[landTokenId].miners[resource][ + minerIndex + ] = lastMiner; + land2ResourceMineState[landTokenId].miners[resource][ + lastMinerIndex + ] = 0; + + land2ResourceMineState[landTokenId].miners[resource].length -= 1; + miner2Index[lastMiner].indexInResource = minerIndex; + + land2ResourceMineState[landTokenId].totalMiners -= 1; + + address miner = + IInterstellarEncoder( + registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER) + ) + .getObjectAddress(_tokenId); + uint256 strength = + IMinerObject(miner).strengthOf(_tokenId, resource, landTokenId); + + // for backward compatibility + // if strength can fluctuate some time in the future + if ( + land2ResourceMineState[landTokenId].totalMinerStrength[resource] != + 0 + ) { + if ( + land2ResourceMineState[landTokenId].totalMinerStrength[ + resource + ] > strength + ) { + land2ResourceMineState[landTokenId].totalMinerStrength[ + resource + ] = land2ResourceMineState[landTokenId].totalMinerStrength[ + resource + ] + .sub(strength); + } else { + land2ResourceMineState[landTokenId].totalMinerStrength[ + resource + ] = 0; + } + } + + if (land2ResourceMineState[landTokenId].totalMiners == 0) { + land2ResourceMineState[landTokenId].totalMinerStrength[ + resource + ] = 0; + } + + delete miner2Index[_tokenId]; + + emit StopMining(_tokenId, landTokenId, resource, strength); + } + + // v5 remove + // function getMinerOnLand( + // uint256 _landTokenId, + // address _resourceToken, + // uint256 _index + // ) public view returns (uint256) { + // return + // land2ResourceMineState[_landTokenId].miners[_resourceToken][_index]; + // } + + // function getTotalMiningStrength( + // uint256 _landTokenId, + // address _resourceToken + // ) public view returns (uint256) { + // return + // land2ResourceMineState[_landTokenId].totalMinerStrength[ + // _resourceToken + // ]; + // } + + // function availableResources( + // uint256 _landTokenId, + // address[5] _resourceTokens + // ) + // public + // view + // returns ( + // uint256, + // uint256, + // uint256, + // uint256, + // uint256 + // ) + // { + // uint256 availableGold = + // _calculateMinedBalance(_landTokenId, _resourceTokens[0], now) + + // land2ResourceMineState[_landTokenId].mintedBalance[ + // _resourceTokens[0] + // ]; + // uint256 availableWood = + // _calculateMinedBalance(_landTokenId, _resourceTokens[1], now) + + // land2ResourceMineState[_landTokenId].mintedBalance[ + // _resourceTokens[1] + // ]; + // uint256 availableWater = + // _calculateMinedBalance(_landTokenId, _resourceTokens[2], now) + + // land2ResourceMineState[_landTokenId].mintedBalance[ + // _resourceTokens[2] + // ]; + // uint256 availableFire = + // _calculateMinedBalance(_landTokenId, _resourceTokens[3], now) + + // land2ResourceMineState[_landTokenId].mintedBalance[ + // _resourceTokens[3] + // ]; + // uint256 availableSoil = + // _calculateMinedBalance(_landTokenId, _resourceTokens[4], now) + + // land2ResourceMineState[_landTokenId].mintedBalance[ + // _resourceTokens[4] + // ]; + + // return ( + // availableGold, + // availableWood, + // availableWater, + // availableFire, + // availableSoil + // ); + // } + + // V5 remove + // function mintedBalanceOnLand(uint256 _landTokenId, address _resourceToken) public view returns (uint256) { + // return land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken]; + // } + + // function landWorkingOn(uint256 _apostleTokenId) public view returns (uint256 landTokenId) { + // landTokenId = miner2Index[_apostleTokenId].landTokenId; + // } + + function _updateMinerStrength(uint256 _apostleTokenId, bool _isStop) + internal + returns (uint256, uint256) + { + // require that this apostle + uint256 landTokenId = landWorkingOn(_apostleTokenId); + require(landTokenId != 0, "this apostle is not mining."); + + address resource = miner2Index[_apostleTokenId].resource; + + address miner = + IInterstellarEncoder( + registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER) + ) + .getObjectAddress(_apostleTokenId); + uint256 strength = + IMinerObject(miner).strengthOf( + _apostleTokenId, + resource, + landTokenId + ); + + mine(landTokenId); + + if (_isStop) { + land2ResourceMineState[landTokenId].totalMinerStrength[ + resource + ] = land2ResourceMineState[landTokenId].totalMinerStrength[resource] + .sub(strength); + } else { + land2ResourceMineState[landTokenId].totalMinerStrength[ + resource + ] += strength; + } + + return (landTokenId, strength); + } + + // when a mirrorToken or a pet has tied to apostle + // we need to update status and remove this apostle from mining list first + // open authority to PetBase + // can only be called by PetBase + function updateMinerStrengthWhenStop(uint256 _apostleTokenId) public auth { + uint256 landTokenId; + uint256 strength; + (landTokenId, strength) = _updateMinerStrength(_apostleTokenId, true); + // _isStop == true - minus strength + // _isStop == false - add strength + emit UpdateMiningStrengthWhenStop( + _apostleTokenId, + landTokenId, + strength + ); + } + + function updateMinerStrengthWhenStart(uint256 _apostleTokenId) public auth { + uint256 landTokenId; + uint256 strength; + (landTokenId, strength) = _updateMinerStrength(_apostleTokenId, false); + // _isStop == true - minus strength + // _isStop == false - add strength + emit UpdateMiningStrengthWhenStart( + _apostleTokenId, + landTokenId, + strength + ); + } + + // V5 add + function getLandMinedBalance(uint256 _landId, address _resource) + public + view + returns (uint256) + { + return land2ResourceMineState[_landId].mintedBalance[_resource]; + } + + function getItemMinedBalance( + address _itemToken, + uint256 _itemId, + address _resource + ) public view returns (uint256) { + return itemMinedBalance[_itemToken][_itemId][_resource]; + } + + function getLandMiningStrength(uint256 _landId, address _resource) + public + view + returns (uint256) + { + return land2ResourceMineState[_landId].totalMinerStrength[_resource]; + } + + function getBarMiningStrength( + uint256 _landId, + address _resource, + uint256 _index + ) public view returns (uint256) { + return + getLandMiningStrength(_landId, _resource) + .mul(getBarRate(_landId, _resource, _index)) + .div(RATE_PRECISION); + } + + function getBarRate( + uint256 _landId, + address _resource, + uint256 _index + ) public view returns (uint256) { + return land2BarRate[_landId][_resource][_index]; + } + + function getBarsRate(uint256 _landId, address _resource) + public + view + returns (uint256 barsRate) + { + for (uint256 i = 0; i < maxAmount; i++) { + barsRate = barsRate.add(getBarRate(_landId, _resource, i)); + } + } + + function getBarsMiningStrength(uint256 _landId, address _resource) + public + view + returns (uint256 barsMiningStrength) + { + return + getLandMiningStrength(_landId, _resource) + .mul(getBarsRate(_landId, _resource)) + .div(RATE_PRECISION); + } + + function getTotalMiningStrength(uint256 _landId, address _resource) + public + view + returns (uint256) + { + return + getLandMiningStrength(_landId, _resource).add( + getBarsMiningStrength(_landId, _resource) + ); + } + + function getMinerOnLand( + uint256 _landId, + address _resource, + uint256 _index + ) public view returns (uint256) { + return land2ResourceMineState[_landId].miners[_resource][_index]; + } + + function landWorkingOn(uint256 _apostleTokenId) + public + view + returns (uint256 landId) + { + landId = miner2Index[_apostleTokenId].landTokenId; + } + + function _getBarRateByIndex( + uint256 _landId, + address _resource, + uint256 _index + ) internal view returns (uint256) { + return enhanceStrengthRateByIndex(_resource, _landId, _index); + } + + function _startBarMining( + uint256 _index, + uint256 _landId, + address _resource + ) internal { + uint256 rate = _getBarRateByIndex(_landId, _resource, _index); + land2BarRate[_landId][_resource][_index] = rate; + emit StartBarMining(_index, _landId, _resource, rate); + } + + function _stopBarMinig( + uint256 _index, + uint256 _landId, + address _resource + ) internal { + delete land2BarRate[_landId][_resource][_index]; + emit StopBarMining(_index, _landId, _resource); + } + + function _claimItemResource( + address _itemToken, + uint256 _itemId, + address _resource + ) internal returns (uint256) { + uint256 balance = getItemMinedBalance(_itemToken, _itemId, _resource); + if (balance > 0) { + IMintableERC20(_resource).mint(msg.sender, balance); + itemMinedBalance[_itemToken][_itemId][_resource] = 0; + return balance; + } else { + return 0; + } + } + + function claimItemResource(address _itemToken, uint256 _itemId) public { + (address staker, uint256 landId) = getLandIdByItem(_itemToken, _itemId); + if (staker == address(0) && landId == 0) { + require( + ERC721(_itemToken).ownerOf(_itemId) == msg.sender, + "Land: ONLY_ITEM_ONWER" + ); + } else { + require(staker == msg.sender, "Land: ONLY_ITEM_STAKER"); + mine(landId); + } + + address gold = registry.addressOf(CONTRACT_GOLD_ERC20_TOKEN); + address wood = registry.addressOf(CONTRACT_WOOD_ERC20_TOKEN); + address water = registry.addressOf(CONTRACT_WATER_ERC20_TOKEN); + address fire = registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN); + address soil = registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN); + uint256 goldBalance = _claimItemResource(_itemToken, _itemId, gold); + uint256 woodBalance = _claimItemResource(_itemToken, _itemId, wood); + uint256 waterBalance = _claimItemResource(_itemToken, _itemId, water); + uint256 fireBalance = _claimItemResource(_itemToken, _itemId, fire); + uint256 soilBalance = _claimItemResource(_itemToken, _itemId, soil); + + emit ItemResourceClaimed( + msg.sender, + _itemToken, + _itemId, + goldBalance, + woodBalance, + waterBalance, + fireBalance, + soilBalance + ); + } + + function _claimLandResource(uint256 _landId, address _resource) + internal + returns (uint256) + { + uint256 balance = getLandMinedBalance(_landId, _resource); + if (balance > 0) { + IMintableERC20(_resource).mint(msg.sender, balance); + land2ResourceMineState[_landId].mintedBalance[_resource] = 0; + return balance; + } else { + return 0; + } + } + + function claimLandResource(uint256 _landId) public { + require( + msg.sender == + ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf( + _landId + ), + "Land: ONLY_LANDER" + ); + + address gold = registry.addressOf(CONTRACT_GOLD_ERC20_TOKEN); + address wood = registry.addressOf(CONTRACT_WOOD_ERC20_TOKEN); + address water = registry.addressOf(CONTRACT_WATER_ERC20_TOKEN); + address fire = registry.addressOf(CONTRACT_FIRE_ERC20_TOKEN); + address soil = registry.addressOf(CONTRACT_SOIL_ERC20_TOKEN); + _mineAllResource(_landId, gold, wood, water, fire, soil); + + uint256 goldBalance = _claimLandResource(_landId, gold); + uint256 woodBalance = _claimLandResource(_landId, wood); + uint256 waterBalance = _claimLandResource(_landId, water); + uint256 fireBalance = _claimLandResource(_landId, fire); + uint256 soilBalance = _claimLandResource(_landId, soil); + + emit LandResourceClaimed( + msg.sender, + _landId, + goldBalance, + woodBalance, + waterBalance, + fireBalance, + soilBalance + ); + } + + function _calculateResources( + address _itemToken, + uint256 _itemId, + uint256 _landId, + address _resource, + uint256 _minedBalance + ) internal view returns (uint256 landBalance, uint256 barResource) { + uint256 barsRate = getBarsRate(_landId, _resource); + // V5 yeild distribution + landBalance = _minedBalance.mul(RATE_PRECISION).div( + barsRate.add(RATE_PRECISION) + ); + if (barsRate > 0) { + uint256 barsBalance = _minedBalance.sub(landBalance); + for (uint256 i = 0; i < maxAmount; i++) { + uint256 barBalance = + barsBalance.mul(getBarRate(_landId, _resource, i)).div( + barsRate + ); + (barBalance, landBalance) = _payFee(barBalance, landBalance); + (address itemToken, uint256 itemId, ) = getBarItem(_landId, i); + if (_itemId == itemId && _itemToken == itemToken) { + barResource = barResource.add(barBalance); + } + } + } + } + + function availableLandResources( + uint256 _landId, + address[] memory _resources + ) public view returns (uint256[] memory) { + uint256[] memory availables = new uint256[](_resources.length); + for (uint256 i = 0; i < _resources.length; i++) { + uint256 mined = _calculateMinedBalance(_landId, _resources[i], now); + (uint256 available, ) = + _calculateResources( + address(0), + 0, + _landId, + _resources[i], + mined + ); + availables[i] = available.add( + getLandMinedBalance(_landId, _resources[i]) + ); + } + return availables; + } + + function availableItemResources( + address _itemToken, + uint256 _itemId, + address[] memory _resources + ) public view returns (uint256[] memory) { + uint256[] memory availables = new uint256[](_resources.length); + for (uint256 i = 0; i < _resources.length; i++) { + (address staker, uint256 landId) = + getLandIdByItem(_itemToken, _itemId); + uint256 available = 0; + if (staker != address(0) && landId != 0) { + uint256 mined = + _calculateMinedBalance(landId, _resources[i], now); + (, uint256 availableItem) = + _calculateResources( + _itemToken, + _itemId, + landId, + _resources[i], + mined + ); + available = available.add(availableItem); + } + available = available.add( + getItemMinedBalance(_itemToken, _itemId, _resources[i]) + ); + availables[i] = available; + } + return availables; + } + + function isNotProtect(address _token, uint256 _id) + public + view + returns (bool) + { + return protectPeriod[_token][_id] < now; + } + + function getBarItem(uint256 _tokenId, uint256 _index) + public + view + returns ( + address, + uint256, + address + ) + { + require(_index < maxAmount, "Furnace: INDEX_FORBIDDEN."); + return ( + landId2Bars[_tokenId][_index].token, + landId2Bars[_tokenId][_index].id, + landId2Bars[_tokenId][_index].resource + ); + } + + function getLandIdByItem(address _item, uint256 _itemId) + public + view + returns (address, uint256) + { + return ( + itemId2Status[_item][_itemId].staker, + itemId2Status[_item][_itemId].tokenId + ); + } + + /** + @dev Equip function, A NFT can equip to EVO Bar (LandBar or ApostleBar). + @param _tokenId Token Id which to be quiped. + @param _resource Which resouce appply to. + @param _index Index of the Bar. + @param _token Token address which to quip. + @param _id Token Id which to quip. + */ + function equip( + uint256 _tokenId, + address _resource, + uint256 _index, + address _token, + uint256 _id + ) public { + _equip(_tokenId, _resource, _index, _token, _id); + } + + function _equip( + uint256 _tokenId, + address _resource, + uint256 _index, + address _token, + uint256 _id + ) internal { + beforeEquip(_tokenId, _resource); + IMetaDataTeller teller = + IMetaDataTeller(registry.addressOf(CONTRACT_METADATA_TELLER)); + uint256 resourceId = + ILandBaseExt(registry.addressOf(CONTRACT_LAND_BASE)) + .resourceToken2RateAttrId(_resource); + require(resourceId > 0 && resourceId < 6, "Furnace: INVALID_RESOURCE"); + require( + IInterstellarEncoder( + registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER) + ) + .getObjectClass(_tokenId) == 1, + "Funace: ONLY_LAND" + ); + (uint16 objClassExt, uint16 class, uint16 grade) = + teller.getMetaData(_token, _id); + require(objClassExt > 0, "Furnace: PERMISSION"); + require(_index < maxAmount, "Furnace: INDEX_FORBIDDEN"); + Bar storage bar = landId2Bars[_tokenId][_index]; + if (bar.token != address(0)) { + require(isNotProtect(bar.token, bar.id), "Furnace: PROTECT_PERIOD"); + (, uint16 originClass, uint16 originGrade) = + teller.getMetaData(bar.token, bar.id); + require( + class > originClass || + (class == originClass && grade > originGrade) || + ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)) + .ownerOf(_tokenId) == + msg.sender, + "Furnace: FORBIDDEN" + ); + //TODO:: safe transfer + ERC721(bar.token).transferFrom(address(this), bar.staker, bar.id); + } + ERC721(_token).transferFrom(msg.sender, address(this), _id); + bar.staker = msg.sender; + bar.token = _token; + bar.id = _id; + bar.resource = _resource; + itemId2Status[bar.token][bar.id] = Status({ + staker: bar.staker, + tokenId: _tokenId, + index: _index + }); + if (isNotProtect(bar.token, bar.id)) { + protectPeriod[bar.token][bar.id] = _calculateProtectPeriod( + bar + .token, + bar + .id, + class + ) + .add(now); + } + afterEquiped(_index, _tokenId, _resource); + emit Equip(_tokenId, _resource, _index, bar.staker, bar.token, bar.id); + } + + function _calculateProtectPeriod( + address _token, + uint256 _id, + uint16 _class + ) internal view returns (uint256) { + uint256 baseProtectPeriod = + registry.uintOf(UINT_ITEMBAR_PROTECT_PERIOD); + return baseProtectPeriod.add(uint256(_class).mul(baseProtectPeriod)); + } + + function beforeEquip(uint256 _landTokenId, address _resource) internal { + if (getLandMiningStrength(_landTokenId, _resource) > 0) { + mine(_landTokenId); + } + } + + function afterEquiped( + uint256 _index, + uint256 _landTokenId, + address _resource + ) internal { + _startBarMining(_index, _landTokenId, _resource); + } + + function afterDivested( + uint256 _index, + uint256 _landTokenId, + address _resource + ) internal { + if (getLandMiningStrength(_landTokenId, _resource) > 0) { + mine(_landTokenId); + } + _stopBarMinig(_index, _landTokenId, _resource); + } + + /** + @dev Divest function, A NFT can Divest from EVO Bar (LandBar or ApostleBar). + @param _tokenId Token Id which to be unquiped. + @param _index Index of the Bar. + */ + function divest(uint256 _tokenId, uint256 _index) public { + _divest(_tokenId, _index); + } + + function _divest(uint256 _tokenId, uint256 _index) internal { + Bar memory bar = landId2Bars[_tokenId][_index]; + require(bar.token != address(0), "Furnace: EMPTY"); + require(bar.staker == msg.sender, "Furnace: FORBIDDEN"); + ERC721(bar.token).transferFrom(address(this), bar.staker, bar.id); + afterDivested(_index, _tokenId, bar.resource); + //clean + delete itemId2Status[bar.token][bar.id]; + delete landId2Bars[_tokenId][_index]; + emit Divest( + _tokenId, + bar.resource, + _index, + bar.staker, + bar.token, + bar.id + ); + } + + function setMaxAmount(uint256 _maxAmount) public auth { + require(_maxAmount > maxAmount, "Furnace: INVALID_MAXAMOUNT"); + maxAmount = _maxAmount; + } + + function enhanceStrengthRateByIndex( + address _resource, + uint256 _tokenId, + uint256 _index + ) public view returns (uint256) { + Bar storage bar = landId2Bars[_tokenId][_index]; + if (bar.token == address(0)) { + return 0; + } + IMetaDataTeller teller = + IMetaDataTeller(registry.addressOf(CONTRACT_METADATA_TELLER)); + uint256 resourceId = + ILandBaseExt(registry.addressOf(CONTRACT_LAND_BASE)) + .resourceToken2RateAttrId(_resource); + return teller.getRate(bar.token, bar.id, resourceId); + } + + function enhanceStrengthRateOf(address _resource, uint256 _tokenId) + external + view + returns (uint256) + { + uint256 rate; + for (uint256 i = 0; i < maxAmount; i++) { + rate = rate.add(enhanceStrengthRateByIndex(_resource, _tokenId, i)); + } + return rate; + } +} From 6941e9773ebbdb413b16e170f2d91892216c3952 Mon Sep 17 00:00:00 2001 From: echo Date: Mon, 26 Apr 2021 00:48:46 +0800 Subject: [PATCH 12/32] dapp uninstall upgradeability-using-unstructured-storage --- .gitmodules | 3 --- lib/upgradeability-using-unstructured-storage | 1 - 2 files changed, 4 deletions(-) delete mode 160000 lib/upgradeability-using-unstructured-storage diff --git a/.gitmodules b/.gitmodules index 35e25c8..6251882 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "lib/upgradeability-using-unstructured-storage"] - path = lib/upgradeability-using-unstructured-storage - url = https://github.com/evolutionlandorg/upgradeability-using-unstructured-storage [submodule "lib/common-contracts"] path = lib/common-contracts url = https://github.com/evolutionlandorg/common-contracts diff --git a/lib/upgradeability-using-unstructured-storage b/lib/upgradeability-using-unstructured-storage deleted file mode 160000 index 5d89ae1..0000000 --- a/lib/upgradeability-using-unstructured-storage +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 5d89ae1a00943cbe06d2fb97ad8ade0f9a7f8f08 From f4a70607142c34db3c476561b57dcc945013f02e Mon Sep 17 00:00:00 2001 From: echo Date: Mon, 26 Apr 2021 10:12:29 +0800 Subject: [PATCH 13/32] rm outdate proxy --- contracts/DeployAndTest.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/DeployAndTest.sol b/contracts/DeployAndTest.sol index 5c64b33..2e83bbc 100644 --- a/contracts/DeployAndTest.sol +++ b/contracts/DeployAndTest.sol @@ -5,7 +5,7 @@ import '@evolutionland/common/contracts/SettingsRegistry.sol'; import '@evolutionland/common/contracts/SettingIds.sol'; import '@evolutionland/common/contracts/StandardERC223.sol'; import '@evolutionland/common/contracts/ObjectOwnership.sol'; -import "@evolutionland/upgraeability-using-unstructured-storage/contracts/OwnedUpgradeabilityProxy.sol"; +// import "@evolutionland/upgraeability-using-unstructured-storage/contracts/OwnedUpgradeabilityProxy.sol"; import "@evolutionland/common/contracts/TokenLocation.sol"; import '@evolutionland/common/contracts/ObjectOwnershipAuthority.sol'; import "@evolutionland/common/contracts/TokenLocationAuthority.sol"; @@ -13,4 +13,4 @@ import "@evolutionland/common/contracts/TokenLocationAuthority.sol"; contract DeployAndTest { -} \ No newline at end of file +} From 456449e734035c4fab28c74272350ceab5dcb286 Mon Sep 17 00:00:00 2001 From: echo Date: Thu, 29 Apr 2021 14:00:05 +0800 Subject: [PATCH 14/32] rm truffle --- .babelrc | 3 - .gitignore | 9 +- contracts/DeployAndTest.sol | 16 --- contracts/LandBaseAuthority.sol | 4 +- contracts/LandResourceAuthority.sol | 4 +- contracts/LandResourceAuthorityV3.sol | 4 +- contracts/Migrations.sol | 25 ---- contracts/MysteriousTreasureAuthority.sol | 4 +- migrations/1_initial_migration.js | 5 - migrations/2_land_migrations.js | 147 ---------------------- migrations/2_land_migrations.js.kovan | 104 --------------- migrations/3_resource_migration.js | 32 ----- migrations/4_upgrade_landResource.js | 19 --- migrations/5_add_auth_to_resources.js | 27 ---- migrations/6_upgrade_landResource_pet.js | 29 ----- package.json | 42 ------- test/Atlantis.test.js | 79 ------------ test/initial/LandInitial.js | 110 ---------------- truffle.js.sample | 33 ----- waffle.json.sample | 9 -- 20 files changed, 10 insertions(+), 695 deletions(-) delete mode 100644 .babelrc delete mode 100644 contracts/DeployAndTest.sol delete mode 100644 contracts/Migrations.sol delete mode 100644 migrations/1_initial_migration.js delete mode 100644 migrations/2_land_migrations.js delete mode 100644 migrations/2_land_migrations.js.kovan delete mode 100644 migrations/3_resource_migration.js delete mode 100644 migrations/4_upgrade_landResource.js delete mode 100644 migrations/5_add_auth_to_resources.js delete mode 100644 migrations/6_upgrade_landResource_pet.js delete mode 100644 package.json delete mode 100644 test/Atlantis.test.js delete mode 100644 test/initial/LandInitial.js delete mode 100644 truffle.js.sample delete mode 100644 waffle.json.sample diff --git a/.babelrc b/.babelrc deleted file mode 100644 index ce6eb60..0000000 --- a/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "presets": ["es2015", "stage-2", "stage-3"] -} diff --git a/.gitignore b/.gitignore index 96f8763..c9389b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,4 @@ -build .DS_Store -node_modules -package-lock.json .idea -truffle.js -waffle.json -cache -out +/out +/flat diff --git a/contracts/DeployAndTest.sol b/contracts/DeployAndTest.sol deleted file mode 100644 index 2e83bbc..0000000 --- a/contracts/DeployAndTest.sol +++ /dev/null @@ -1,16 +0,0 @@ -pragma solidity ^0.4.23; - -import '@evolutionland/common/contracts/InterstellarEncoder.sol'; -import '@evolutionland/common/contracts/SettingsRegistry.sol'; -import '@evolutionland/common/contracts/SettingIds.sol'; -import '@evolutionland/common/contracts/StandardERC223.sol'; -import '@evolutionland/common/contracts/ObjectOwnership.sol'; -// import "@evolutionland/upgraeability-using-unstructured-storage/contracts/OwnedUpgradeabilityProxy.sol"; -import "@evolutionland/common/contracts/TokenLocation.sol"; -import '@evolutionland/common/contracts/ObjectOwnershipAuthority.sol'; -import "@evolutionland/common/contracts/TokenLocationAuthority.sol"; - - -contract DeployAndTest { - -} diff --git a/contracts/LandBaseAuthority.sol b/contracts/LandBaseAuthority.sol index 1f6c12a..752bd45 100644 --- a/contracts/LandBaseAuthority.sol +++ b/contracts/LandBaseAuthority.sol @@ -11,11 +11,11 @@ contract LandBaseAuthority { mapping (address => bool) public whiteList; function canCall( - address _src, address _dst, bytes4 _sig + address _src, address /*_dst*/, bytes4 _sig ) public view returns (bool) { return ( whiteList[_src] && _sig == bytes4(keccak256("setResourceRateAttr(uint256,uint256)")) ) || ( whiteList[_src] && _sig == bytes4(keccak256("setResourceRate(uint256,address,uint16)")) ) || ( whiteList[_src] && _sig == bytes4(keccak256("setHasBox(uint256,bool)"))) || ( whiteList[_src] && _sig == bytes4(keccak256("assignNewLand(int256,int256,address,uint256,uint256)"))); } -} \ No newline at end of file +} diff --git a/contracts/LandResourceAuthority.sol b/contracts/LandResourceAuthority.sol index 5c926e7..102a491 100644 --- a/contracts/LandResourceAuthority.sol +++ b/contracts/LandResourceAuthority.sol @@ -11,8 +11,8 @@ contract LandResourceAuthority { mapping (address => bool) public whiteList; function canCall( - address _src, address _dst, bytes4 _sig + address _src, address /*_dst*/, bytes4 _sig ) public view returns (bool) { return ( whiteList[_src] && _sig == bytes4(keccak256("activityStopped(uint256)"))); } -} \ No newline at end of file +} diff --git a/contracts/LandResourceAuthorityV3.sol b/contracts/LandResourceAuthorityV3.sol index 4c5ea47..337e4f6 100644 --- a/contracts/LandResourceAuthorityV3.sol +++ b/contracts/LandResourceAuthorityV3.sol @@ -11,10 +11,10 @@ contract LandResourceAuthorityV3 { mapping (address => bool) public whiteList; function canCall( - address _src, address _dst, bytes4 _sig + address _src, address /*_dst*/, bytes4 _sig ) public view returns (bool) { return ( whiteList[_src] && _sig == bytes4(keccak256("activityStopped(uint256)"))) || ( whiteList[_src] && _sig == bytes4(keccak256("updateMinerStrengthWhenStop(uint256)"))) || ( whiteList[_src] && _sig == bytes4(keccak256("updateMinerStrengthWhenStart(uint256)"))); } -} \ No newline at end of file +} diff --git a/contracts/Migrations.sol b/contracts/Migrations.sol deleted file mode 100644 index 085d869..0000000 --- a/contracts/Migrations.sol +++ /dev/null @@ -1,25 +0,0 @@ -pragma solidity ^0.4.24; - -import "@evolutionland/common/contracts/StandardERC223.sol"; -import "@evolutionland/common/contracts/MintAndBurnAuthority.sol"; -contract Migrations { - address public owner; - uint public last_completed_migration; - - constructor() public { - owner = msg.sender; - } - - modifier restricted() { - if (msg.sender == owner) _; - } - - function setCompleted(uint completed) public restricted { - last_completed_migration = completed; - } - - function upgrade(address new_address) public restricted { - Migrations upgraded = Migrations(new_address); - upgraded.setCompleted(last_completed_migration); - } -} diff --git a/contracts/MysteriousTreasureAuthority.sol b/contracts/MysteriousTreasureAuthority.sol index 1bd8fdd..fb442ec 100644 --- a/contracts/MysteriousTreasureAuthority.sol +++ b/contracts/MysteriousTreasureAuthority.sol @@ -11,8 +11,8 @@ contract MysteriousTreasureAuthority { mapping (address => bool) public whiteList; function canCall( - address _src, address _dst, bytes4 _sig + address _src, address /*_dst*/, bytes4 _sig ) public view returns (bool) { return whiteList[_src]; } -} \ No newline at end of file +} diff --git a/migrations/1_initial_migration.js b/migrations/1_initial_migration.js deleted file mode 100644 index 4d5f3f9..0000000 --- a/migrations/1_initial_migration.js +++ /dev/null @@ -1,5 +0,0 @@ -var Migrations = artifacts.require("./Migrations.sol"); - -module.exports = function(deployer) { - deployer.deploy(Migrations); -}; diff --git a/migrations/2_land_migrations.js b/migrations/2_land_migrations.js deleted file mode 100644 index 8c459a9..0000000 --- a/migrations/2_land_migrations.js +++ /dev/null @@ -1,147 +0,0 @@ -const StandardERC223 = artifacts.require('StandardERC223'); -const InterstellarEncoder = artifacts.require('InterstellarEncoder'); -const SettingsRegistry = artifacts.require('SettingsRegistry'); -const SettingIds = artifacts.require('SettingIds'); -const LandBase = artifacts.require('LandBase'); -const ObjectOwnership = artifacts.require('ObjectOwnership'); -const Proxy = artifacts.require('OwnedUpgradeabilityProxy'); -const LandBaseAuthority = artifacts.require('LandBaseAuthority'); -const ObjectOwnershipAuthority = artifacts.require('ObjectOwnershipAuthority'); -const TokenLocationAuthority = artifacts.require('TokenLocationAuthority') -const TokenLocation = artifacts.require('TokenLocation'); - -const conf = { - land_objectClass: 1 -} - -let gold_address; -let wood_address; -let water_address; -let fire_address; -let soil_address; - -let landBaseProxy_address; -let objectOwnershipProxy_address; -let tokenLocationProxy_address; - -module.exports = async (deployer, network, accounts) => { - - if(network == 'kovan') { - return; - } - - deployer.deploy(StandardERC223, "GOLD" - ).then(async() => { - let gold = await StandardERC223.deployed(); - gold_address = gold.address; - return deployer.deploy(StandardERC223, "WOOD") - }).then(async() => { - let wood = await StandardERC223.deployed(); - wood_address = wood.address; - return deployer.deploy(StandardERC223, "WATER") - }).then(async() => { - let water = await StandardERC223.deployed(); - water_address = water.address; - return deployer.deploy(StandardERC223, "FIRE") - }).then(async () => { - let fire = await StandardERC223.deployed(); - fire_address = fire.address; - return deployer.deploy(StandardERC223, "SOIL") - }).then(async() => { - let soil = await StandardERC223.deployed(); - soil_address = soil.address; - await deployer.deploy(SettingIds); - await deployer.deploy(SettingsRegistry); - await deployer.deploy(TokenLocation); - await deployer.deploy(Proxy); - await deployer.deploy(LandBase) - }).then(async () => { - let tokenLocationProxy = await Proxy.deployed(); - tokenLocationProxy_address = tokenLocationProxy.address; - console.log("tokenLocation proxy: ", tokenLocationProxy.address); - return deployer.deploy(Proxy); - }).then(async() => { - let landBaseProxy = await Proxy.deployed(); - landBaseProxy_address = landBaseProxy.address; - console.log("landBase proxy: ", landBaseProxy_address); - await deployer.deploy(Proxy); - return Proxy.deployed(); - }).then(async() => { - await deployer.deploy(ObjectOwnership); - let objectOwnershipProxy = await Proxy.deployed(); - objectOwnershipProxy_address = objectOwnershipProxy.address; - console.log("objectOwnership proxy: ", objectOwnershipProxy_address); - await deployer.deploy(ObjectOwnershipAuthority, [landBaseProxy_address]); - await deployer.deploy(TokenLocationAuthority, [landBaseProxy_address]); - await deployer.deploy(InterstellarEncoder); - }).then(async () => { - - let settingIds = await SettingIds.deployed(); - let settingsRegistry = await SettingsRegistry.deployed(); - - let goldId = await settingIds.CONTRACT_GOLD_ERC20_TOKEN.call(); - let woodId = await settingIds.CONTRACT_WOOD_ERC20_TOKEN.call(); - let waterId = await settingIds.CONTRACT_WATER_ERC20_TOKEN.call(); - let fireId = await settingIds.CONTRACT_FIRE_ERC20_TOKEN.call(); - let soilId = await settingIds.CONTRACT_SOIL_ERC20_TOKEN.call(); - - // register resouces to registry - await settingsRegistry.setAddressProperty(goldId, gold_address); - await settingsRegistry.setAddressProperty(woodId, wood_address); - await settingsRegistry.setAddressProperty(waterId, water_address); - await settingsRegistry.setAddressProperty(fireId, fire_address); - await settingsRegistry.setAddressProperty(soilId, soil_address); - - let interstellarEncoder = await InterstellarEncoder.deployed(); - let interstellarEncoderId = await settingIds.CONTRACT_INTERSTELLAR_ENCODER.call(); - await settingsRegistry.setAddressProperty(interstellarEncoderId, interstellarEncoder.address); - - - let landBase = await LandBase.deployed(); - let objectOwnership = await ObjectOwnership.deployed(); - let tokenLocation = await TokenLocation.deployed(); - - // register in registry - let objectOwnershipId = await settingIds.CONTRACT_OBJECT_OWNERSHIP.call(); - let landBaseId = await settingIds.CONTRACT_LAND_BASE.call(); - let tokenLocationId = await settingIds.CONTRACT_TOKEN_LOCATION.call(); - await settingsRegistry.setAddressProperty(landBaseId,landBaseProxy_address); - await settingsRegistry.setAddressProperty(objectOwnershipId, objectOwnershipProxy_address); - await settingsRegistry.setAddressProperty(tokenLocationId, tokenLocationProxy_address); - - console.log("REGISTER DONE!"); - // upgrade - await Proxy.at(landBaseProxy_address).upgradeTo(LandBase.address); - await Proxy.at(objectOwnershipProxy_address).upgradeTo(ObjectOwnership.address); - await Proxy.at(tokenLocationProxy_address).upgradeTo(TokenLocation.address); - console.log("UPGRADE DONE!"); - - // verify proxies' implementations - let landBase_impl = await Proxy.at(landBaseProxy_address).implementation(); - console.log("landBase_impl: ", landBase_impl); - let objectOwnership_impl = await Proxy.at(objectOwnershipProxy_address).implementation() - console.log("objectOwnership_impl: ", objectOwnership_impl); - let tokenLocation_impl = await Proxy.at(tokenLocationProxy_address).implementation(); - console.log("tokenLocation_impl: ", tokenLocation_impl); - - let tokenLocationProxy = await TokenLocation.at(tokenLocationProxy_address); - await tokenLocationProxy.initializeContract(); - let landProxy = await LandBase.at(landBaseProxy_address); - await landProxy.initializeContract(settingsRegistry.address); - let objectOwnershipProxy = await ObjectOwnership.at(objectOwnershipProxy_address); - await objectOwnershipProxy.initializeContract(settingsRegistry.address); - - console.log("INITIALIZE DONE!"); - // set authority - await tokenLocationProxy.setAuthority(TokenLocationAuthority.address); - await ObjectOwnership.at(objectOwnershipProxy_address).setAuthority(ObjectOwnershipAuthority.address); - - - await interstellarEncoder.registerNewTokenContract(objectOwnershipProxy_address); - await interstellarEncoder.registerNewObjectClass(landBaseProxy_address, conf.land_objectClass); - - console.log('MIGRATION SUCCESS!'); - - }) - -} \ No newline at end of file diff --git a/migrations/2_land_migrations.js.kovan b/migrations/2_land_migrations.js.kovan deleted file mode 100644 index cfc4457..0000000 --- a/migrations/2_land_migrations.js.kovan +++ /dev/null @@ -1,104 +0,0 @@ -const StandardERC223 = artifacts.require('StandardERC223'); -const InterstellarEncoder = artifacts.require('InterstellarEncoder'); -const SettingsRegistry = artifacts.require('SettingsRegistry'); -const SettingIds = artifacts.require('SettingIds'); -const LandBase = artifacts.require('LandBase'); -const ObjectOwnership = artifacts.require('ObjectOwnership'); -const Proxy = artifacts.require('OwnedUpgradeabilityProxy'); -const Authority = artifacts.require('Authority'); -const TokenLocation = artifacts.require('TokenLocation'); - -var conf = { - from: '0x4cc4c344eba849dc09ac9af4bff1977e44fc1d7e', - settingsId_address: '0x3c7a503bd56a6afcdbe57286f2e4d8063719c73f', - registry_address: '0x31ff7a0106cae24756a62657660e3878dcec77dc', - gold_address: '0x2417a2146967cacebf67890ce8772ae260ef2985', - wood_address: '0x2c0fa985dc11f5dc520a621fb4b87924a81be1e5', - water_address: '0x83001f4d8b59b35b745414c4058ac24e127e462d', - fire_address: '0x6efb629ef747b9272257b32eed574c1af6cbf76b', - soil_address: '0x5d57b3c0befe188fb0095b538a60e7dc2590b0d3', - tokenLocation_address: '0x6b10af57f7b5e712af66825b82a6e9c2cd6e184d', - landBaseProxy_address: '0xc1e900b3bd2e79b2d0c406bdc2b03acc4b891cd5', - objectOwnershipProxy_address: '0xa1a9e23152230c5faa3b5a735ccac856dbb132a6', - settingsId_address: '0x7d1bee7c0f7a8ba3ec3d6bd4a7596a21cc0ab9c2', - landBase_address: '0x3a3496b235bab58e3f42d35071dcda227f1b643b', - objectOwnership_address: '0xde9e85ec15b2b9103a62301bf2e3b3e229ed156b', - authority_address: '0x233169105e0e95fe2cbca29098dcb48715b263dd', - interstellarEncoder_address: '0x282d2ae3395f3b47cb54d1da8efc1572252d343b' - -} -let landBaseProxy; -let objectOwnershipProxy; - -module.exports = async (deployer, network, accounts) => { - if (network != "kovan") { - return; - } - // - // deployer.deploy(SettingIds); - // deployer.deploy(TokenLocation); - // deployer.deploy(LandBase); - // deployer.deploy(Proxy).then(async() => { - // landBaseProxy = await Proxy.deployed(); - // console.log("landBase proxy: ", landBaseProxy.address); - // await deployer.deploy(ObjectOwnership); - // await deployer.deploy(Proxy); - // return Proxy.deployed(); - // }).then(async(proxy) => { - // await deployer.deploy(Authority, landBaseProxy.address); - // objectOwnershipProxy = await proxy; - // console.log("objectOwnership proxy: ", objectOwnershipProxy.address); - deployer.deploy(Proxy).then(async () => { - let settingsId = await SettingIds.at(conf.settingsId_address); - let settingsRegistry = await SettingsRegistry.at(conf.registry_address); - - // let goldId = await settingsId.CONTRACT_GOLD_ERC20_TOKEN.call(); - // let woodId = await settingsId.CONTRACT_WOOD_ERC20_TOKEN.call(); - // let waterId = await settingsId.CONTRACT_WATER_ERC20_TOKEN.call(); - // let fireId = await settingsId.CONTRACT_FIRE_ERC20_TOKEN.call(); - // let soilId = await settingsId.CONTRACT_SOIL_ERC20_TOKEN.call(); - // - // // register resouces to registry - // await settingsRegistry.setAddressProperty(goldId, conf.gold_address); - // await settingsRegistry.setAddressProperty(woodId, conf.wood_address); - // await settingsRegistry.setAddressProperty(waterId, conf.water_address); - // await settingsRegistry.setAddressProperty(fireId, conf.fire_address); - // await settingsRegistry.setAddressProperty(soilId, conf.soil_address); - - let interstellarEncoder = await InterstellarEncoder.at(conf.interstellarEncoder_address); - let interstellarEncoderId = await settingsId.CONTRACT_INTERSTELLAR_ENCODER.call(); - await settingsRegistry.setAddressProperty(interstellarEncoderId, interstellarEncoder.address); - - await interstellarEncoder.registerNewTokenContract(conf.objectOwnershipProxy_address); - await interstellarEncoder.registerNewObjectClass(conf.landBaseProxy_address, 1); - - - // let landBase = await LandBase.at(conf.landBase_address); - // let objectOwnership = await ObjectOwnership.at(conf.objectOwnership_address); - // - // landBaseProxy = await Proxy.at(conf.landBaseProxy_address); - // objectOwnershipProxy = await Proxy.at(conf.objectOwnershipProxy_address); - // - // let impl1 = await landBaseProxy.implementation(); - // console.log("impl1: ", impl1); - // - // // upgrade - // // await landBaseProxy.upgradeTo(landBase.address); - // // await objectOwnershipProxy.upgradeTo(conf.objectOwnership_address); - // let impl2 = await objectOwnershipProxy.implementation() - // console.log("impl2: ", impl2); - // - // let tokenLocation = await TokenLocation.at(conf.tokenLocation_address); - // // await LandBase.at(landBaseProxy.address).initializeContract(conf.registry_address, tokenLocation.address); - // await ObjectOwnership.at(objectOwnershipProxy.address).initializeContract(conf.registry_address); - // - // // set authority - // let authority = await Authority.at(conf.authority_address); - // await tokenLocation.setAuthority(authority.address); - // await ObjectOwnership.at(objectOwnershipProxy.address).setAuthority(authority.address); - console.log('Intialize Successfully!') - - - }) - -} \ No newline at end of file diff --git a/migrations/3_resource_migration.js b/migrations/3_resource_migration.js deleted file mode 100644 index e28623e..0000000 --- a/migrations/3_resource_migration.js +++ /dev/null @@ -1,32 +0,0 @@ -const Proxy = artifacts.require('OwnedUpgradeabilityProxy'); -const LandResource = artifacts.require('LandResource'); -const LandResourceAuthority = artifacts.require('LandResourceAuthority'); - -const conf = { - registry_address: '0xd8b7a3f6076872c2c37fb4d5cbfeb5bf45826ed7', - tokenUseProxy_address: '0xd2bcd143db59ddd43df2002fbf650e46b2b7ea19' -} - -module.exports = async(deployer, network) => { - if(network == 'kovan') { - return; - } - - deployer.deploy(Proxy); - deployer.deploy(LandResource).then(async() => { - await deployer.deploy(LandResourceAuthority, [conf.tokenUseProxy_address]) - }).then(async() => { - await Proxy.at(Proxy.address).upgradeTo(LandResource.address); - console.log("UPGRADE DONE!"); - - let landResourceProxy = await LandResource.at(Proxy.address); - await landResourceProxy.initializeContract(conf.registry_address, 1544083267); - console.log("INITIALIZE DONE!"); - - await landResourceProxy.setAuthority(LandResourceAuthority.address); - - console.log('MIGRATION SUCCESS!'); - - - }) -} \ No newline at end of file diff --git a/migrations/4_upgrade_landResource.js b/migrations/4_upgrade_landResource.js deleted file mode 100644 index 3851273..0000000 --- a/migrations/4_upgrade_landResource.js +++ /dev/null @@ -1,19 +0,0 @@ -const Proxy = artifacts.require('OwnedUpgradeabilityProxy'); -const LandResourceV2 = artifacts.require('LandResourceV2'); - -const conf = { - landResourceProxy_address: '0x6bcb3c94040ba63e4da086f2a8d0d6f5f72b8490' -} - -module.exports = async (deployer, network) => { - - if (network == 'kovan') { - return; - } - - deployer.deploy(LandResourceV2).then(async () => { - await Proxy.at(conf.landResourceProxy_address).upgradeTo(LandResourceV2.address); - }) - - -} \ No newline at end of file diff --git a/migrations/5_add_auth_to_resources.js b/migrations/5_add_auth_to_resources.js deleted file mode 100644 index fc4c968..0000000 --- a/migrations/5_add_auth_to_resources.js +++ /dev/null @@ -1,27 +0,0 @@ -const StandardERC223 = artifacts.require('StandardERC223') -const MintAndBurnAuthority = artifacts.require('MintAndBurnAuthority'); - -const conf = { - gold_address: '0xf2b3aeba2fd26eb9c7af802e728069f1c217e565', - wood_address: '0x9314fc7e0a2825f5b2a38bed43ddfdf1b30216b1', - water_address: '0xbffb29084e610ffea58bbd81f044cdb68979babd', - fire_address: '0x5f405a65b67a2ba03ffd1fdf20e0e92b50e41ae3', - soil_address: '0x8a768e5dafa2950b0d0a686d45b5226ffeb24aa6', - landResourceProxy_address: '0x6bcb3c94040ba63e4da086f2a8d0d6f5f72b8490' -} - -module.exports = async(deployer, network) => { - - if(network == 'kovan') { - return; - } - - - deployer.deploy(MintAndBurnAuthority, [conf.landResourceProxy_address]).then(async() => { - await StandardERC223.at(conf.gold_address).setAuthority(MintAndBurnAuthority.address); - await StandardERC223.at(conf.wood_address).setAuthority(MintAndBurnAuthority.address); - await StandardERC223.at(conf.water_address).setAuthority(MintAndBurnAuthority.address); - await StandardERC223.at(conf.fire_address).setAuthority(MintAndBurnAuthority.address); - await StandardERC223.at(conf.soil_address).setAuthority(MintAndBurnAuthority.address); - }) -} \ No newline at end of file diff --git a/migrations/6_upgrade_landResource_pet.js b/migrations/6_upgrade_landResource_pet.js deleted file mode 100644 index 69faa66..0000000 --- a/migrations/6_upgrade_landResource_pet.js +++ /dev/null @@ -1,29 +0,0 @@ -const Proxy = artifacts.require('OwnedUpgradeabilityProxy'); -const LandResourceV3 = artifacts.require('LandResourceV3'); -const LandResourceAuthorityV3 = artifacts.require("LandResourceAuthorityV3"); - -const conf = { - landResourceProxy_address: '0x6bcb3c94040ba63e4da086f2a8d0d6f5f72b8490', - tokenUseProxy_address: '0xd2bcd143db59ddd43df2002fbf650e46b2b7ea19', - petBaseProxy_address: '0x9038cf766688c8e9b19552f464b514f9760fdc49' -} - -module.exports = async (deployer, network) => { - - if (network != 'kovan') { - return; - } - - deployer.deploy(LandResourceV3).then(async () => { - await Proxy.at(conf.landResourceProxy_address).upgradeTo(LandResourceV3.address); - await deployer.deploy(LandResourceAuthorityV3, [conf.tokenUseProxy_address, conf.petBaseProxy_address]); - }).then(async() => { - - // setAuthority - let landResourceProxy = await LandResourceV3.at(conf.landResourceProxy_address); - await landResourceProxy.setAuthority(LandResourceAuthorityV3.address); - - }) - - -} \ No newline at end of file diff --git a/package.json b/package.json deleted file mode 100644 index c040da5..0000000 --- a/package.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name": "@evolutionland/land", - "version": "1.4.1", - "description": "Land Contracts for Evolution Land", - "main": "truffle-config.js", - "scripts": { - "build": "npx waffle", - "flatten": "npx waffle flatten" - }, - "directories": { - "test": "test" - }, - "dependencies": { - "@evolutionland/common": "^1.7.1", - "@evolutionland/upgraeability-using-unstructured-storage": "^0.1.1", - "babel-polyfill": "^6.26.0", - "babel-preset-es2015": "^6.18.0", - "babel-preset-stage-2": "^6.24.1", - "babel-preset-stage-3": "^6.17.0", - "babel-register": "^6.23.0", - "mocha": "^5.2.0", - "openzeppelin-solidity": "^1.12.0", - "solc": "^0.4.24", - "truffle-hdwallet-provider": "0.0.5", - "truffle-privatekey-provider": "^0.1.0", - "web3": "^1.0.0-beta.34" - }, - "devDependencies": { - "ethereum-waffle": "^3.2.1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/evolutionlandorg/land.git" - }, - "keywords": [], - "author": "", - "license": "ISC", - "bugs": { - "url": "https://github.com/evolutionlandorg/land/issues" - }, - "homepage": "https://github.com/evolutionlandorg/land#readme" -} diff --git a/test/Atlantis.test.js b/test/Atlantis.test.js deleted file mode 100644 index 28f4298..0000000 --- a/test/Atlantis.test.js +++ /dev/null @@ -1,79 +0,0 @@ -const StandardERC223 = artifacts.require('StandardERC223'); -const InterstellarEncoder = artifacts.require('InterstellarEncoder'); -const SettingsRegistry = artifacts.require('SettingsRegistry'); -const SettingIds = artifacts.require('SettingIds'); -const LandBase = artifacts.require('LandBase'); -const ObjectOwnership = artifacts.require('ObjectOwnership'); -const Proxy = artifacts.require('OwnedUpgradeabilityProxy'); -const ObjectOwnershipAuthority = artifacts.require('ObjectOwnershipAuthority'); -const TokenLocationAuthority = artifacts.require('TokenLocationAuthority'); -const TokenLocation = artifacts.require('TokenLocation'); -const initial = require('./initial/LandInitial'); -var initiateLand = initial.initiateLand; -const Web3 = require('web3'); -var web3 = new Web3(Web3.givenProvider); - -var from = '0x4cc4c344eba849dc09ac9af4bff1977e44fc1d7e'; - -contract('Land series contracts', async (accounts) => { - let gold; - let wood; - let water; - let fire; - let soil; - let landBase; - let objectOwnership; - let tokenLocation; - let interstellarEncoder; - let landBaseProxy; - - before('intialize', async () => { - var initlal = await initiateLand(accounts); - gold = initlal.gold; - wood = initlal.wood; - water = initlal.water; - fire = initlal.fire; - soil = initlal.soil; - landBase = initlal.landBase; - objectOwnership = initlal.objectOwnership; - tokenLocation = initlal.tokenLocation; - interstellarEncoder = initlal.interstellarEncoder; - }) - - it('test initialization', async () => { - let cancall1 = await ObjectOwnershipAuthority.at(await objectOwnership.authority()).canCall(landBase.address, objectOwnership.address, - web3.eth.abi.encodeFunctionSignature('mintObject(address,uint128)')); - assert(cancall1, 'cancall1 should be true'); - let cancall2 = await TokenLocationAuthority.at(await tokenLocation.authority()).canCall(landBase.address, tokenLocation.address, - web3.eth.abi.encodeFunctionSignature('setTokenLocationHM(uint256,int256,int256)')); - assert(cancall2, 'cancall2 should be true'); - }) - - it('assign new land', async () => { - // let attr = 100 + 99 * 65536 + 98 * 65536 * 65536 + 97 * 65536 * 65536 * 65536 + 96 * 65536 * 65536 * 65536 * 65536; - // let attr = 1770914734569771171940; - // console.log(attr); - let tokenId = await landBase.assignNewLand(-90, 13, from - , "1770914734569771171940", 4); - console.log("tokenId: ", tokenId.valueOf()); - let tokenOne = await interstellarEncoder.encodeTokenIdForObjectContract(objectOwnership.address, landBase.address, 1); - console.log("tokenOne: ", tokenOne.valueOf()); - // console.log("tokenOne: ", tokenOne.toNubmer()); - let owner = await objectOwnership.ownerOf(tokenOne); - assert.equal(owner, from); - - let xxx = await landBase.getResourceRateAttr.call(tokenOne.valueOf()) - console.log(xxx.valueOf()); - - assert.equal((await landBase.getResourceRate.call(tokenOne.valueOf(), gold.address)).toNumber(), 100); - assert.equal((await landBase.getResourceRate.call(tokenOne.valueOf(), wood.address)).toNumber(), 99); - assert.equal((await landBase.getResourceRate.call(tokenOne.valueOf(), water.address)).toNumber(), 98); - assert.equal((await landBase.getResourceRate.call(tokenOne.valueOf(), fire.address)).toNumber(), 97); - assert.equal((await landBase.getResourceRate.call(tokenOne.valueOf(), soil.address)).toNumber(), 96); - - await landBase.setResourceRate(tokenOne.valueOf(), water.address, 88); - - assert.equal((await landBase.getResourceRate.call(tokenOne.valueOf(), water.address)).toNumber(), 88); - }) - -}) \ No newline at end of file diff --git a/test/initial/LandInitial.js b/test/initial/LandInitial.js deleted file mode 100644 index 27dc9ac..0000000 --- a/test/initial/LandInitial.js +++ /dev/null @@ -1,110 +0,0 @@ -const StandardERC223 = artifacts.require('StandardERC223'); -const InterstellarEncoder = artifacts.require('InterstellarEncoder'); -const SettingsRegistry = artifacts.require('SettingsRegistry'); -const SettingIds = artifacts.require('SettingIds'); -const LandBase = artifacts.require('LandBase'); -const ObjectOwnership = artifacts.require('ObjectOwnership'); -const Proxy = artifacts.require('OwnedUpgradeabilityProxy'); -const LandBaseAuthority = artifacts.require('LandBaseAuthority'); -const ObjectOwnershipAuthority = artifacts.require('ObjectOwnershipAuthority'); -const TokenLocationAuthority = artifacts.require('TokenLocationAuthority') -const TokenLocation = artifacts.require('TokenLocation'); - -module.exports = { - initiateLand : initiateLand -} - -async function initiateLand(accounts) { - let settingsRegistry = await SettingsRegistry.new(); - console.log('SettingsRegistry address : ', settingsRegistry.address); - let gold = await StandardERC223.new("GOLD"); - console.log('gold address : ', gold.address); - let wood = await StandardERC223.new("WOOD"); - console.log('wood address : ', wood.address); - let water = await StandardERC223.new("WATER"); - console.log('water address : ', water.address); - let fire = await StandardERC223.new("FIRE"); - console.log('fire address : ', fire.address); - let soil = await StandardERC223.new("SOIL"); - console.log('soil address : ', soil.address); - - let settingsId = await SettingIds.new(); - - let goldId = await settingsId.CONTRACT_GOLD_ERC20_TOKEN.call(); - let woodId = await settingsId.CONTRACT_WOOD_ERC20_TOKEN.call(); - let waterId = await settingsId.CONTRACT_WATER_ERC20_TOKEN.call(); - let fireId = await settingsId.CONTRACT_FIRE_ERC20_TOKEN.call(); - let soilId = await settingsId.CONTRACT_SOIL_ERC20_TOKEN.call(); - - // register resouces to registry - await settingsRegistry.setAddressProperty(goldId, gold.address); - await settingsRegistry.setAddressProperty(woodId, wood.address); - await settingsRegistry.setAddressProperty(waterId, water.address); - await settingsRegistry.setAddressProperty(fireId, fire.address); - await settingsRegistry.setAddressProperty(soilId, soil.address); - - // new contracts with proxy - let tokenLocation = await TokenLocation.new(); - console.log('tokenLocation address : ', tokenLocation.address); - let tokenLocationProxy = await Proxy.new(); - console.log('tokenLocationProxy address : ', tokenLocationProxy.address); - - let landBase = await LandBase.new({gas: 6000000}); - console.log('landBase address : ', landBase.address); - let landBaseProxy = await Proxy.new(); - console.log('landBaseProxy address : ', landBaseProxy.address); - - let objectOwnership = await ObjectOwnership.new(); - console.log('objectOwnership implementation: ', await objectOwnership.address); - let objectOwnershipProxy = await Proxy.new(); - console.log('objectOwnershipProxy implementation: ', await objectOwnershipProxy.address); - - // register to settingsRegisty - let tokenLocationId = await settingsId.CONTRACT_TOKEN_LOCATION.call(); - await settingsRegistry.setAddressProperty(tokenLocationId, tokenLocationProxy.address); - - let landBaseId = await settingsId.CONTRACT_LAND_BASE.call(); - await settingsRegistry.setAddressProperty(landBaseId, landBaseProxy.address); - - let objectOwnershipId = await settingsId.CONTRACT_OBJECT_OWNERSHIP.call(); - await settingsRegistry.setAddressProperty(objectOwnershipId, objectOwnershipProxy.address); - - let interstellarEncoder = await InterstellarEncoder.new(); - console.log("interstellarEncoder address: ", interstellarEncoder.address); - - let interstellarEncoderId = await settingsId.CONTRACT_INTERSTELLAR_ENCODER.call(); - await settingsRegistry.setAddressProperty(interstellarEncoderId, interstellarEncoder.address); - - await interstellarEncoder.registerNewTokenContract(objectOwnershipProxy.address); - await interstellarEncoder.registerNewObjectClass(landBaseProxy.address, 1); - - - // let authority = await Authority.new(landBaseProxy.address); - let landBaseAuthority = await LandBaseAuthority.new(); - let objectOwnershipAuthority = await ObjectOwnershipAuthority.new(); - let tokenLocationAuthority = await TokenLocationAuthority.new(); - - await objectOwnershipAuthority.setWhitelist(landBaseProxy.address, true); - await tokenLocationAuthority.setWhitelist(landBaseProxy.address, true); - - // upgrade - await tokenLocationProxy.upgradeTo(tokenLocation.address); - await landBaseProxy.upgradeTo(landBase.address); - await objectOwnershipProxy.upgradeTo(objectOwnership.address); - - await TokenLocation.at(tokenLocationProxy.address).initializeContract(); - await ObjectOwnership.at(objectOwnershipProxy.address).initializeContract(settingsRegistry.address); - await LandBase.at(landBaseProxy.address).initializeContract(settingsRegistry.address); - - // set authority - await TokenLocation.at(tokenLocationProxy.address).setAuthority(tokenLocationAuthority.address); - await ObjectOwnership.at(objectOwnershipProxy.address).setAuthority(objectOwnershipAuthority.address); - console.log('Intialize Successfully!') - - return {landBase: LandBase.at(landBaseProxy.address), objectOwnership: - ObjectOwnership.at(objectOwnershipProxy.address), - tokenLocation: TokenLocation.at(tokenLocationProxy.address), - interstellarEncoder: interstellarEncoder, - gold: gold, wood: wood, water: water, fire: fire, soil: soil} - -} \ No newline at end of file diff --git a/truffle.js.sample b/truffle.js.sample deleted file mode 100644 index 40fd0e3..0000000 --- a/truffle.js.sample +++ /dev/null @@ -1,33 +0,0 @@ -var HDWalletProvider = require("truffle-hdwallet-provider"); -var mnemonic = "letter allow maze torch giggle cotton culture honey dream win opera egg"; // 12 word mnemonic -var provider = new HDWalletProvider(mnemonic, "https://kovan.infura.io/sv2WF26MzGmjjevuh9hX "); - -module.exports = { - - - networks: { - development: { - host: "127.0.0.1", - port: 8545, - network_id: "*" // Match any network id - }, - kovan: { - provider: function() { - return provider; - }, - network_id: "*" - }, - ganache: { - host: "127.0.0.1", - port: 7545, - network_id: "*" - } - }, - solc: { - optimizer: { - enabled: true, - runs: 200 - } - } -} - diff --git a/waffle.json.sample b/waffle.json.sample deleted file mode 100644 index f30f8d3..0000000 --- a/waffle.json.sample +++ /dev/null @@ -1,9 +0,0 @@ -{ - "sourceDirectory": "./contracts", - "outputDirectory": "./build", - "nodeModulesDirectory": "./node_modules", - "flattenOutputDirectory": "./flat", - "cacheDirectory": "./cache", - "compilerType": "solcjs", - "compilerVersion": "0.4.24" -} From 5b99fbd0e57a52f1d065d3c5db9679e189a5dd84 Mon Sep 17 00:00:00 2001 From: echo Date: Thu, 29 Apr 2021 14:06:20 +0800 Subject: [PATCH 15/32] fix warning --- contracts/LandResource.sol | 4 ++-- contracts/LandResourceV2.sol | 4 ++-- contracts/LandResourceV3.sol | 4 ++-- contracts/LandResourceV4.sol | 4 ++-- contracts/LandResourceV5.sol | 10 +--------- contracts/LandResourceV6.sol | 10 +--------- contracts/MysteriousTreasureAuthority.sol | 2 +- 7 files changed, 11 insertions(+), 27 deletions(-) diff --git a/contracts/LandResource.sol b/contracts/LandResource.sol index 9a8c137..1d7e7e7 100644 --- a/contracts/LandResource.sol +++ b/contracts/LandResource.sol @@ -195,7 +195,7 @@ contract LandResource is SupportsInterfaceWithLookup, DSAuth, IActivity, LandSet land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken] += minedBalance; } - function _calculateMinedBalance(uint256 _landTokenId, address _resourceToken, uint256 _currentTime) internal returns (uint256) { + function _calculateMinedBalance(uint256 _landTokenId, address _resourceToken, uint256 _currentTime) internal view returns (uint256) { uint256 currentTime = _currentTime; uint256 minedBalance; @@ -400,4 +400,4 @@ contract LandResource is SupportsInterfaceWithLookup, DSAuth, IActivity, LandSet return land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken]; } -} \ No newline at end of file +} diff --git a/contracts/LandResourceV2.sol b/contracts/LandResourceV2.sol index 176bc99..ff7dc3c 100644 --- a/contracts/LandResourceV2.sol +++ b/contracts/LandResourceV2.sol @@ -195,7 +195,7 @@ contract LandResourceV2 is SupportsInterfaceWithLookup, DSAuth, IActivity, LandS land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken] += minedBalance; } - function _calculateMinedBalance(uint256 _landTokenId, address _resourceToken, uint256 _currentTime) internal returns (uint256) { + function _calculateMinedBalance(uint256 _landTokenId, address _resourceToken, uint256 _currentTime) internal view returns (uint256) { uint256 currentTime = _currentTime; uint256 minedBalance; @@ -400,4 +400,4 @@ contract LandResourceV2 is SupportsInterfaceWithLookup, DSAuth, IActivity, LandS return land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken]; } -} \ No newline at end of file +} diff --git a/contracts/LandResourceV3.sol b/contracts/LandResourceV3.sol index 3bd152c..883926d 100644 --- a/contracts/LandResourceV3.sol +++ b/contracts/LandResourceV3.sol @@ -204,7 +204,7 @@ contract LandResourceV3 is SupportsInterfaceWithLookup, DSAuth, IActivity, LandS land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken] += minedBalance; } - function _calculateMinedBalance(uint256 _landTokenId, address _resourceToken, uint256 _currentTime) internal returns (uint256) { + function _calculateMinedBalance(uint256 _landTokenId, address _resourceToken, uint256 _currentTime) internal view returns (uint256) { uint256 currentTime = _currentTime; uint256 minedBalance; @@ -459,4 +459,4 @@ contract LandResourceV3 is SupportsInterfaceWithLookup, DSAuth, IActivity, LandS emit UpdateMiningStrengthWhenStart(_apostleTokenId, landTokenId, strength); } -} \ No newline at end of file +} diff --git a/contracts/LandResourceV4.sol b/contracts/LandResourceV4.sol index d9de675..eabc33f 100644 --- a/contracts/LandResourceV4.sol +++ b/contracts/LandResourceV4.sol @@ -204,7 +204,7 @@ contract LandResourceV4 is SupportsInterfaceWithLookup, DSAuth, IActivity, LandS land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken] += minedBalance; } - function _calculateMinedBalance(uint256 _landTokenId, address _resourceToken, uint256 _currentTime) internal returns (uint256) { + function _calculateMinedBalance(uint256 _landTokenId, address _resourceToken, uint256 _currentTime) internal view returns (uint256) { uint256 currentTime = _currentTime; uint256 minedBalance; @@ -467,4 +467,4 @@ contract LandResourceV4 is SupportsInterfaceWithLookup, DSAuth, IActivity, LandS emit UpdateMiningStrengthWhenStart(_apostleTokenId, landTokenId, strength); } -} \ No newline at end of file +} diff --git a/contracts/LandResourceV5.sol b/contracts/LandResourceV5.sol index 5f5fff2..cc53c8d 100644 --- a/contracts/LandResourceV5.sol +++ b/contracts/LandResourceV5.sol @@ -1309,13 +1309,7 @@ contract LandResourceV5 is SupportsInterfaceWithLookup, DSAuth, IActivity { index: _index }); if (isNotProtect(bar.token, bar.id)) { - protectPeriod[bar.token][bar.id] = _calculateProtectPeriod( - bar - .token, - bar - .id, - class - ) + protectPeriod[bar.token][bar.id] = _calculateProtectPeriod(class) .add(now); } afterEquiped(_index, _tokenId, _resource); @@ -1323,8 +1317,6 @@ contract LandResourceV5 is SupportsInterfaceWithLookup, DSAuth, IActivity { } function _calculateProtectPeriod( - address _token, - uint256 _id, uint16 _class ) internal view returns (uint256) { uint256 baseProtectPeriod = diff --git a/contracts/LandResourceV6.sol b/contracts/LandResourceV6.sol index 27660fd..d352609 100644 --- a/contracts/LandResourceV6.sol +++ b/contracts/LandResourceV6.sol @@ -1312,13 +1312,7 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { index: _index }); if (isNotProtect(bar.token, bar.id)) { - protectPeriod[bar.token][bar.id] = _calculateProtectPeriod( - bar - .token, - bar - .id, - class - ) + protectPeriod[bar.token][bar.id] = _calculateProtectPeriod(class) .add(now); } afterEquiped(_index, _tokenId, _resource); @@ -1326,8 +1320,6 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { } function _calculateProtectPeriod( - address _token, - uint256 _id, uint16 _class ) internal view returns (uint256) { uint256 baseProtectPeriod = diff --git a/contracts/MysteriousTreasureAuthority.sol b/contracts/MysteriousTreasureAuthority.sol index fb442ec..c8049ec 100644 --- a/contracts/MysteriousTreasureAuthority.sol +++ b/contracts/MysteriousTreasureAuthority.sol @@ -11,7 +11,7 @@ contract MysteriousTreasureAuthority { mapping (address => bool) public whiteList; function canCall( - address _src, address /*_dst*/, bytes4 _sig + address _src, address /*_dst*/, bytes4 /*_sig*/ ) public view returns (bool) { return whiteList[_src]; } From 3d9bd7d0d14f046834578215e97ab32b8ce368f9 Mon Sep 17 00:00:00 2001 From: echo Date: Thu, 6 May 2021 16:54:33 +0800 Subject: [PATCH 16/32] make flat --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 5775c51..93f8904 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,3 @@ all :; source .env && dapp --use solc:0.4.24 build clean :; dapp clean +flat :; source .env && dapp --use solc:0.4.24 flat From 16165643376f2444f19d7761dbfe95d5d049d0e6 Mon Sep 17 00:00:00 2001 From: echo Date: Mon, 10 May 2021 10:24:59 +0800 Subject: [PATCH 17/32] fix base v2 storage loc --- contracts/LandBaseV2.sol | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contracts/LandBaseV2.sol b/contracts/LandBaseV2.sol index 8117f4f..32c7db7 100644 --- a/contracts/LandBaseV2.sol +++ b/contracts/LandBaseV2.sol @@ -27,11 +27,6 @@ contract LandBaseV2 is DSAuth, ILandBase, SettingIds { ISettingsRegistry public registry; - int256 xLow; - int256 xHigh; - int256 yLow; - int256 yHigh; - /** * @dev mapping from resource token address to resource atrribute rate id. * atrribute rate id starts from 1 to 16, NAN is 0. @@ -49,6 +44,11 @@ contract LandBaseV2 is DSAuth, ILandBase, SettingIds { uint256 public lastLandObjectId; + int256 xLow; + int256 xHigh; + int256 yLow; + int256 yHigh; + /* * Modifiers */ From aaa2a15538a9742c841a43f639acf89c22da7471 Mon Sep 17 00:00:00 2001 From: echo Date: Thu, 27 May 2021 14:20:14 +0800 Subject: [PATCH 18/32] fix certik audit --- contracts/LandResourceV6.sol | 63 ++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/contracts/LandResourceV6.sol b/contracts/LandResourceV6.sol index d352609..a128e79 100644 --- a/contracts/LandResourceV6.sol +++ b/contracts/LandResourceV6.sol @@ -14,6 +14,7 @@ import "./interfaces/ILandBase.sol"; import "./interfaces/ILandBaseExt.sol"; import "./interfaces/IMetaDataTeller.sol"; +// DSAuth see https://github.com/evolutionlandorg/common-contracts/blob/2873a4f8f970bd442ffcf9c6ae63b3dc79e743db/contracts/DSAuth.sol#L40 contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { using SafeMath for *; @@ -142,6 +143,9 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { uint256 id ); + event SetMaxLandBar(uint256 maxAmount); + event SetMaxMiner(uint256 maxMiners); + // 0x434f4e54524143545f4c414e445f424153450000000000000000000000000000 bytes32 public constant CONTRACT_LAND_BASE = "CONTRACT_LAND_BASE"; @@ -234,10 +238,13 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { singletonLock = true; } + // initializeContract be called by proxy contract + // see https://blog.openzeppelin.com/the-transparent-proxy-pattern/ function initializeContract( address _registry, uint256 _resourceReleaseStartTime ) public singletonLockCall { + require(_registry!= address(0), "_registry is a zero value"); // Ownable constructor owner = msg.sender; emit LogSetOwner(msg.sender); @@ -246,6 +253,7 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { resourceReleaseStartTime = _resourceReleaseStartTime; + //see https://github.com/evolutionlandorg/common-contracts/blob/2873a4f8f970bd442ffcf9c6ae63b3dc79e743db/contracts/interfaces/IActivity.sol#L6 _registerInterface(InterfaceId_IActivity); maxMiners = 5; @@ -316,6 +324,10 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { .div(TOTAL_SECONDS); } + // For every seconds, the speed will decrease by current speed multiplying (DENOMINATOR_in_seconds - seconds) / DENOMINATOR_in_seconds. + // resource will decrease 1/10000 every day. + // `minableBalance` is an area of a trapezoid. + // The reason for dividing by `1 days` twice is that the definition of `getResourceRate` is the number of mines that can be mined per day. function _getMinableBalance( uint256 _tokenId, address _resource, @@ -357,6 +369,7 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { function setMaxMiners(uint256 _maxMiners) public auth { require(_maxMiners > maxMiners, "Land: INVALID_MAXMINERS"); maxMiners = _maxMiners; + emit SetMaxMiner(maxMiners); } function mine(uint256 _landTokenId) public { @@ -494,7 +507,7 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { uint256 lastUpdateTime = land2ResourceMineState[_landTokenId].lastUpdateTime; - require(currentTime >= lastUpdateTime); + require(currentTime >= lastUpdateTime, "Land: INVALID_TIMESTAMP"); if (lastUpdateTime >= (resourceReleaseStartTime + TOTAL_SECONDS)) { minedBalance = 0; @@ -516,7 +529,7 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { if (minedBalance > minableBalance) { minedBalance = minableBalance; - } + } return minedBalance; } @@ -593,12 +606,6 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { uint256 _landTokenId, address _resource ) public { - ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).addActivity( - _tokenId, - msg.sender, - 0 - ); - // require the permission from land owner; require( msg.sender == @@ -611,6 +618,12 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { // make sure that _tokenId won't be used repeatedly require(miner2Index[_tokenId].landTokenId == 0); + ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).addActivity( + _tokenId, + msg.sender, + 0 + ); + // update status! mine(_landTokenId); @@ -638,9 +651,7 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { IMinerObject(miner).strengthOf(_tokenId, _resource, _landTokenId); land2ResourceMineState[_landTokenId].miners[_resource].push(_tokenId); - land2ResourceMineState[_landTokenId].totalMinerStrength[ - _resource - ] += strength; + land2ResourceMineState[_landTokenId].totalMinerStrength[_resource] = land2ResourceMineState[_landTokenId].totalMinerStrength[_resource].add(strength); miner2Index[_tokenId] = MinerStatus({ landTokenId: _landTokenId, @@ -655,7 +666,7 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { uint256[] _tokenIds, uint256[] _landTokenIds, address[] _resources - ) public { + ) external { require( _tokenIds.length == _landTokenIds.length && _landTokenIds.length == _resources.length, @@ -668,7 +679,7 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { } } - function batchClaimLandResource(uint256[] _landTokenIds) public { + function batchClaimLandResource(uint256[] _landTokenIds) external { uint256 length = _landTokenIds.length; for (uint256 i = 0; i < length; i++) { @@ -715,7 +726,7 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { lastMinerIndex ] = 0; - land2ResourceMineState[landTokenId].miners[resource].length -= 1; + land2ResourceMineState[landTokenId].miners[resource].length = land2ResourceMineState[landTokenId].miners[resource].length.sub(1); miner2Index[lastMiner].indexInResource = minerIndex; land2ResourceMineState[landTokenId].totalMiners -= 1; @@ -871,9 +882,7 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { ] = land2ResourceMineState[landTokenId].totalMinerStrength[resource] .sub(strength); } else { - land2ResourceMineState[landTokenId].totalMinerStrength[ - resource - ] += strength; + land2ResourceMineState[landTokenId].totalMinerStrength[resource] = land2ResourceMineState[landTokenId].totalMinerStrength[resource].add(strength); } return (landTokenId, strength); @@ -1048,7 +1057,7 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { if (staker == address(0) && landId == 0) { require( ERC721(_itemToken).ownerOf(_itemId) == msg.sender, - "Land: ONLY_ITEM_ONWER" + "Land: ONLY_ITEM_OWNER" ); } else { require(staker == msg.sender, "Land: ONLY_ITEM_STAKER"); @@ -1155,8 +1164,8 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { function availableLandResources( uint256 _landId, - address[] memory _resources - ) public view returns (uint256[] memory) { + address[] _resources + ) external view returns (uint256[] memory) { uint256[] memory availables = new uint256[](_resources.length); for (uint256 i = 0; i < _resources.length; i++) { uint256 mined = _calculateMinedBalance(_landId, _resources[i], now); @@ -1178,8 +1187,8 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { function availableItemResources( address _itemToken, uint256 _itemId, - address[] memory _resources - ) public view returns (uint256[] memory) { + address[] _resources + ) external view returns (uint256[] memory) { uint256[] memory availables = new uint256[](_resources.length); for (uint256 i = 0; i < _resources.length; i++) { (address staker, uint256 landId) = @@ -1352,6 +1361,11 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { _stopBarMinig(_index, _landTokenId, _resource); } + function devestAndClaim(address _itemToken, uint256 _tokenId, uint256 _index) public { + divest(_tokenId, _index); + claimItemResource(_itemToken, _tokenId); + } + /** @dev Divest function, A NFT can Divest from EVO Bar (LandBar or ApostleBar). @param _tokenId Token Id which to be unquiped. @@ -1381,8 +1395,9 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { } function setMaxAmount(uint256 _maxAmount) public auth { - require(_maxAmount > maxAmount, "Furnace: INVALID_MAXAMOUNT"); - maxAmount = _maxAmount; + require(_maxAmount > maxAmount, "Furnace: INVALID_MAXAMOUNT"); + maxAmount = _maxAmount; + emit SetMaxLandBar(maxAmount); } function enhanceStrengthRateByIndex( From 261eca14c59cbd8bc76fadb74c5897f2f192673a Mon Sep 17 00:00:00 2001 From: echo Date: Thu, 27 May 2021 14:26:12 +0800 Subject: [PATCH 19/32] Update LandResourceV6.sol --- contracts/LandResourceV6.sol | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/contracts/LandResourceV6.sol b/contracts/LandResourceV6.sol index a128e79..a033ed8 100644 --- a/contracts/LandResourceV6.sol +++ b/contracts/LandResourceV6.sol @@ -143,8 +143,8 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { uint256 id ); - event SetMaxLandBar(uint256 maxAmount); - event SetMaxMiner(uint256 maxMiners); + event SetMaxLandBar(uint256 maxAmount); + event SetMaxMiner(uint256 maxMiners); // 0x434f4e54524143545f4c414e445f424153450000000000000000000000000000 bytes32 public constant CONTRACT_LAND_BASE = "CONTRACT_LAND_BASE"; @@ -238,8 +238,8 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { singletonLock = true; } - // initializeContract be called by proxy contract - // see https://blog.openzeppelin.com/the-transparent-proxy-pattern/ + // initializeContract be called by proxy contract + // see https://blog.openzeppelin.com/the-transparent-proxy-pattern/ function initializeContract( address _registry, uint256 _resourceReleaseStartTime @@ -253,11 +253,11 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { resourceReleaseStartTime = _resourceReleaseStartTime; - //see https://github.com/evolutionlandorg/common-contracts/blob/2873a4f8f970bd442ffcf9c6ae63b3dc79e743db/contracts/interfaces/IActivity.sol#L6 + //see https://github.com/evolutionlandorg/common-contracts/blob/2873a4f8f970bd442ffcf9c6ae63b3dc79e743db/contracts/interfaces/IActivity.sol#L6 _registerInterface(InterfaceId_IActivity); - maxMiners = 5; - maxAmount = 5; + maxMiners = 5; + maxAmount = 5; } // get amount of speed uint at this moment @@ -326,8 +326,8 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { // For every seconds, the speed will decrease by current speed multiplying (DENOMINATOR_in_seconds - seconds) / DENOMINATOR_in_seconds. // resource will decrease 1/10000 every day. - // `minableBalance` is an area of a trapezoid. - // The reason for dividing by `1 days` twice is that the definition of `getResourceRate` is the number of mines that can be mined per day. + // `minableBalance` is an area of a trapezoid. + // The reason for dividing by `1 days` twice is that the definition of `getResourceRate` is the number of mines that can be mined per day. function _getMinableBalance( uint256 _tokenId, address _resource, @@ -1258,7 +1258,7 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { @param _index Index of the Bar. @param _token Token address which to quip. @param _id Token Id which to quip. - */ + */ function equip( uint256 _tokenId, address _resource, @@ -1361,16 +1361,16 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { _stopBarMinig(_index, _landTokenId, _resource); } - function devestAndClaim(address _itemToken, uint256 _tokenId, uint256 _index) public { - divest(_tokenId, _index); - claimItemResource(_itemToken, _tokenId); - } + function devestAndClaim(address _itemToken, uint256 _tokenId, uint256 _index) public { + divest(_tokenId, _index); + claimItemResource(_itemToken, _tokenId); + } /** @dev Divest function, A NFT can Divest from EVO Bar (LandBar or ApostleBar). @param _tokenId Token Id which to be unquiped. @param _index Index of the Bar. - */ + */ function divest(uint256 _tokenId, uint256 _index) public { _divest(_tokenId, _index); } From 85f1dba901fa2da51603a00fea7ada60dec872cc Mon Sep 17 00:00:00 2001 From: echo Date: Fri, 4 Jun 2021 17:52:40 +0800 Subject: [PATCH 20/32] fix loc range invisible --- contracts/LandBaseV2.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/LandBaseV2.sol b/contracts/LandBaseV2.sol index 32c7db7..cc28298 100644 --- a/contracts/LandBaseV2.sol +++ b/contracts/LandBaseV2.sol @@ -44,10 +44,10 @@ contract LandBaseV2 is DSAuth, ILandBase, SettingIds { uint256 public lastLandObjectId; - int256 xLow; - int256 xHigh; - int256 yLow; - int256 yHigh; + int256 public xLow; + int256 public xHigh; + int256 public yLow; + int256 public yHigh; /* * Modifiers From a1c49c708eedf2251abc5f7d1dafe6f121800fe4 Mon Sep 17 00:00:00 2001 From: echo Date: Fri, 2 Jul 2021 21:02:39 +0800 Subject: [PATCH 21/32] fix: drill period --- contracts/LandResourceV6.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/LandResourceV6.sol b/contracts/LandResourceV6.sol index a033ed8..c38ba95 100644 --- a/contracts/LandResourceV6.sol +++ b/contracts/LandResourceV6.sol @@ -1333,7 +1333,7 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { ) internal view returns (uint256) { uint256 baseProtectPeriod = registry.uintOf(UINT_ITEMBAR_PROTECT_PERIOD); - return baseProtectPeriod.add(uint256(_class).mul(baseProtectPeriod)); + return uint256(_class).mul(baseProtectPeriod); } function beforeEquip(uint256 _landTokenId, address _resource) internal { From 7462759973fcb39fb0aa90230554192624b2e33e Mon Sep 17 00:00:00 2001 From: echo Date: Fri, 16 Jul 2021 14:12:23 +0800 Subject: [PATCH 22/32] lnd: fix item to status issue --- contracts/LandResourceV6.sol | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contracts/LandResourceV6.sol b/contracts/LandResourceV6.sol index c38ba95..6518e5f 100644 --- a/contracts/LandResourceV6.sol +++ b/contracts/LandResourceV6.sol @@ -1309,6 +1309,15 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { ); //TODO:: safe transfer ERC721(bar.token).transferFrom(address(this), bar.staker, bar.id); + delete itemId2Status[bar.staker][bar.id]; + // emit Divest( + // _tokenId, + // bar.resource, + // _index, + // bar.staker, + // bar.token, + // bar.id + // ); } ERC721(_token).transferFrom(msg.sender, address(this), _id); bar.staker = msg.sender; From e94b85ccad5d5054bb5369249c2522237fca1260 Mon Sep 17 00:00:00 2001 From: echo Date: Wed, 21 Jul 2021 12:46:29 +0800 Subject: [PATCH 23/32] makefile: PHONY --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 93f8904..28b51e3 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ all :; source .env && dapp --use solc:0.4.24 build clean :; dapp clean flat :; source .env && dapp --use solc:0.4.24 flat + +.PHONY: all clean flat From abd8bbdf54dc4b8ac0e5b00e102e298d05f5ff75 Mon Sep 17 00:00:00 2001 From: echo Date: Wed, 4 Aug 2021 13:47:21 +0800 Subject: [PATCH 24/32] land owner have right to stop mining --- contracts/LandResourceV6.sol | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/contracts/LandResourceV6.sol b/contracts/LandResourceV6.sol index 6518e5f..d4d6652 100644 --- a/contracts/LandResourceV6.sol +++ b/contracts/LandResourceV6.sol @@ -693,10 +693,14 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { } function stopMining(uint256 _tokenId) public { - ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).removeActivity( - _tokenId, - msg.sender - ); + if (ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(_tokenId) == msg.sender) { + ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).removeActivity(_tokenId, msg.sender); + } else { + // Land owner has right to stop mining + uint256 landTokenId = miner2Index[_tokenId].landTokenId; + require(msg.sender == ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(landTokenId), "Land: ONLY_LANDER"); + ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).removeActivity(_tokenId, address(0)); + } } function _stopMining(uint256 _tokenId) internal { From 58a2b1606cfbb4aaf100b742d7c3722bc0ca881a Mon Sep 17 00:00:00 2001 From: echo Date: Wed, 4 Aug 2021 13:57:19 +0800 Subject: [PATCH 25/32] fmt --- contracts/LandResourceV6.sol | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/contracts/LandResourceV6.sol b/contracts/LandResourceV6.sol index d4d6652..b9dc82a 100644 --- a/contracts/LandResourceV6.sol +++ b/contracts/LandResourceV6.sol @@ -693,14 +693,14 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { } function stopMining(uint256 _tokenId) public { - if (ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(_tokenId) == msg.sender) { - ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).removeActivity(_tokenId, msg.sender); - } else { - // Land owner has right to stop mining - uint256 landTokenId = miner2Index[_tokenId].landTokenId; - require(msg.sender == ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(landTokenId), "Land: ONLY_LANDER"); - ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).removeActivity(_tokenId, address(0)); - } + if (ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(_tokenId) == msg.sender) { + ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).removeActivity(_tokenId, msg.sender); + } else { + // Land owner has right to stop mining + uint256 landTokenId = miner2Index[_tokenId].landTokenId; + require(msg.sender == ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(landTokenId), "Land: ONLY_LANDER"); + ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).removeActivity(_tokenId, address(0)); + } } function _stopMining(uint256 _tokenId) internal { From 84975252ee40d629ba214650a47210292ffdc2f2 Mon Sep 17 00:00:00 2001 From: echo Date: Wed, 4 Aug 2021 15:08:55 +0800 Subject: [PATCH 26/32] land owner have right to stop mining during the lease --- contracts/LandResourceV6.sol | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/contracts/LandResourceV6.sol b/contracts/LandResourceV6.sol index b9dc82a..6f8db3d 100644 --- a/contracts/LandResourceV6.sol +++ b/contracts/LandResourceV6.sol @@ -693,13 +693,16 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { } function stopMining(uint256 _tokenId) public { - if (ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(_tokenId) == msg.sender) { - ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).removeActivity(_tokenId, msg.sender); + address ownership = registry.addressOf(CONTRACT_OBJECT_OWNERSHIP); + address tokenuse = registry.addressOf(CONTRACT_TOKEN_USE); + if (ERC721(ownership).ownerOf(_tokenId) == msg.sender) { + ITokenUse(tokenuse).removeActivity(_tokenId, msg.sender); } else { // Land owner has right to stop mining uint256 landTokenId = miner2Index[_tokenId].landTokenId; - require(msg.sender == ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).ownerOf(landTokenId), "Land: ONLY_LANDER"); - ITokenUse(registry.addressOf(CONTRACT_TOKEN_USE)).removeActivity(_tokenId, address(0)); + require(msg.sender == ERC721(ownership).ownerOf(landTokenId), "Land: ONLY_LANDER"); + address user = ITokenUse(tokenuse).getTokenUser(_tokenId); + ITokenUse(tokenuse).removeActivity(_tokenId, user); } } From e95bf31e22ad2c4095540c1d8f87f758f274df7e Mon Sep 17 00:00:00 2001 From: echo Date: Wed, 11 Aug 2021 15:44:30 +0800 Subject: [PATCH 27/32] batch claim item resource --- contracts/LandResourceV6.sol | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contracts/LandResourceV6.sol b/contracts/LandResourceV6.sol index 6f8db3d..048b100 100644 --- a/contracts/LandResourceV6.sol +++ b/contracts/LandResourceV6.sol @@ -687,6 +687,14 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { } } + function batchClaimItemResource(address[] _itemTokens, uint256[] _itemIds) external { + require(_itemTokens.length == _itemIds.length, "Land: INVALID_LENGTH"); + uint256 length = _itemTokens.length; + for (uint256 i = 0; i < length; i++) { + claimItemResource(_itemTokens[i], _itemIds[i]); + } + } + // Only trigger from Token Activity. function activityStopped(uint256 _tokenId) public auth { _stopMining(_tokenId); From f2283ff8ebf5a7305b65c42ea4157fd47e63b2f4 Mon Sep 17 00:00:00 2001 From: echo Date: Wed, 11 Aug 2021 16:10:16 +0800 Subject: [PATCH 28/32] fmt --- contracts/LandResourceV6.sol | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/contracts/LandResourceV6.sol b/contracts/LandResourceV6.sol index 048b100..9be8f1b 100644 --- a/contracts/LandResourceV6.sol +++ b/contracts/LandResourceV6.sol @@ -687,13 +687,13 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { } } - function batchClaimItemResource(address[] _itemTokens, uint256[] _itemIds) external { - require(_itemTokens.length == _itemIds.length, "Land: INVALID_LENGTH"); - uint256 length = _itemTokens.length; - for (uint256 i = 0; i < length; i++) { - claimItemResource(_itemTokens[i], _itemIds[i]); + function batchClaimItemResource(address[] _itemTokens, uint256[] _itemIds) external { + require(_itemTokens.length == _itemIds.length, "Land: INVALID_LENGTH"); + uint256 length = _itemTokens.length; + for (uint256 i = 0; i < length; i++) { + claimItemResource(_itemTokens[i], _itemIds[i]); + } } - } // Only trigger from Token Activity. function activityStopped(uint256 _tokenId) public auth { From 1a5cad7df41b887589365c2060dd272ac4ddaeae Mon Sep 17 00:00:00 2001 From: echo Date: Wed, 11 Aug 2021 16:11:32 +0800 Subject: [PATCH 29/32] fmt --- contracts/LandResourceV6.sol | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/contracts/LandResourceV6.sol b/contracts/LandResourceV6.sol index 9be8f1b..9a6d985 100644 --- a/contracts/LandResourceV6.sol +++ b/contracts/LandResourceV6.sol @@ -701,17 +701,17 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { } function stopMining(uint256 _tokenId) public { - address ownership = registry.addressOf(CONTRACT_OBJECT_OWNERSHIP); - address tokenuse = registry.addressOf(CONTRACT_TOKEN_USE); - if (ERC721(ownership).ownerOf(_tokenId) == msg.sender) { - ITokenUse(tokenuse).removeActivity(_tokenId, msg.sender); - } else { - // Land owner has right to stop mining - uint256 landTokenId = miner2Index[_tokenId].landTokenId; - require(msg.sender == ERC721(ownership).ownerOf(landTokenId), "Land: ONLY_LANDER"); - address user = ITokenUse(tokenuse).getTokenUser(_tokenId); - ITokenUse(tokenuse).removeActivity(_tokenId, user); - } + address ownership = registry.addressOf(CONTRACT_OBJECT_OWNERSHIP); + address tokenuse = registry.addressOf(CONTRACT_TOKEN_USE); + if (ERC721(ownership).ownerOf(_tokenId) == msg.sender) { + ITokenUse(tokenuse).removeActivity(_tokenId, msg.sender); + } else { + // Land owner has right to stop mining + uint256 landTokenId = miner2Index[_tokenId].landTokenId; + require(msg.sender == ERC721(ownership).ownerOf(landTokenId), "Land: ONLY_LANDER"); + address user = ITokenUse(tokenuse).getTokenUser(_tokenId); + ITokenUse(tokenuse).removeActivity(_tokenId, user); + } } function _stopMining(uint256 _tokenId) internal { From 2946df03f6d91d8e2982bbc65d3f5f9eec5a8d20 Mon Sep 17 00:00:00 2001 From: echo Date: Mon, 23 Aug 2021 14:47:18 +0800 Subject: [PATCH 30/32] abi --- abi/DSAuth.abi | 1 + abi/DSAuthEvents.abi | 1 + abi/ERC165.abi | 1 + abi/ERC721.abi | 1 + abi/ERC721Basic.abi | 1 + abi/ERC721Enumerable.abi | 1 + abi/ERC721Metadata.abi | 1 + abi/IActivity.abi | 1 + abi/IAuthority.abi | 1 + abi/IInterstellarEncoder.abi | 1 + abi/ILandBase.abi | 1 + abi/ILandBaseExt.abi | 1 + abi/IMetaDataTeller.abi | 1 + abi/IMinerObject.abi | 1 + abi/IMintableERC20.abi | 1 + abi/IMysteriousTreasure.abi | 1 + abi/IObjectOwnership.abi | 1 + abi/ISettingsRegistry.abi | 1 + abi/ITokenLocation.abi | 1 + abi/ITokenUse.abi | 1 + abi/LandBase.abi | 1 + abi/LandBaseAuthority.abi | 1 + abi/LandBaseV2.abi | 1 + abi/LandResource.abi | 1 + abi/LandResourceAuthority.abi | 1 + abi/LandResourceAuthorityV3.abi | 1 + abi/LandResourceV2.abi | 1 + abi/LandResourceV3.abi | 1 + abi/LandResourceV4.abi | 1 + abi/LandResourceV5.abi | 1 + abi/LandResourceV6.abi | 1 + abi/LandSettingIds.abi | 1 + abi/LocationCoder.abi | 1 + abi/MysteriousTreasure.abi | 1 + abi/MysteriousTreasureAuthority.abi | 1 + abi/SafeMath.abi | 1 + abi/SettingIds.abi | 1 + abi/SupportsInterfaceWithLookup.abi | 1 + 38 files changed, 38 insertions(+) create mode 100644 abi/DSAuth.abi create mode 100644 abi/DSAuthEvents.abi create mode 100644 abi/ERC165.abi create mode 100644 abi/ERC721.abi create mode 100644 abi/ERC721Basic.abi create mode 100644 abi/ERC721Enumerable.abi create mode 100644 abi/ERC721Metadata.abi create mode 100644 abi/IActivity.abi create mode 100644 abi/IAuthority.abi create mode 100644 abi/IInterstellarEncoder.abi create mode 100644 abi/ILandBase.abi create mode 100644 abi/ILandBaseExt.abi create mode 100644 abi/IMetaDataTeller.abi create mode 100644 abi/IMinerObject.abi create mode 100644 abi/IMintableERC20.abi create mode 100644 abi/IMysteriousTreasure.abi create mode 100644 abi/IObjectOwnership.abi create mode 100644 abi/ISettingsRegistry.abi create mode 100644 abi/ITokenLocation.abi create mode 100644 abi/ITokenUse.abi create mode 100644 abi/LandBase.abi create mode 100644 abi/LandBaseAuthority.abi create mode 100644 abi/LandBaseV2.abi create mode 100644 abi/LandResource.abi create mode 100644 abi/LandResourceAuthority.abi create mode 100644 abi/LandResourceAuthorityV3.abi create mode 100644 abi/LandResourceV2.abi create mode 100644 abi/LandResourceV3.abi create mode 100644 abi/LandResourceV4.abi create mode 100644 abi/LandResourceV5.abi create mode 100644 abi/LandResourceV6.abi create mode 100644 abi/LandSettingIds.abi create mode 100644 abi/LocationCoder.abi create mode 100644 abi/MysteriousTreasure.abi create mode 100644 abi/MysteriousTreasureAuthority.abi create mode 100644 abi/SafeMath.abi create mode 100644 abi/SettingIds.abi create mode 100644 abi/SupportsInterfaceWithLookup.abi diff --git a/abi/DSAuth.abi b/abi/DSAuth.abi new file mode 100644 index 0000000..be1f375 --- /dev/null +++ b/abi/DSAuth.abi @@ -0,0 +1 @@ +[{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"}] diff --git a/abi/DSAuthEvents.abi b/abi/DSAuthEvents.abi new file mode 100644 index 0000000..4183aa3 --- /dev/null +++ b/abi/DSAuthEvents.abi @@ -0,0 +1 @@ +[{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"}] diff --git a/abi/ERC165.abi b/abi/ERC165.abi new file mode 100644 index 0000000..32bba35 --- /dev/null +++ b/abi/ERC165.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"}] diff --git a/abi/ERC721.abi b/abi/ERC721.abi new file mode 100644 index 0000000..66d5423 --- /dev/null +++ b/abi/ERC721.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"_name","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"name":"_operator","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"name":"_tokenId","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"exists","outputs":[{"name":"_exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"name":"_owner","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"_balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"_symbol","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_operator","type":"address"},{"name":"_approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"},{"name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":true,"name":"_tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_approved","type":"address"},{"indexed":true,"name":"_tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_operator","type":"address"},{"indexed":false,"name":"_approved","type":"bool"}],"name":"ApprovalForAll","type":"event"}] diff --git a/abi/ERC721Basic.abi b/abi/ERC721Basic.abi new file mode 100644 index 0000000..86ea9fd --- /dev/null +++ b/abi/ERC721Basic.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"name":"_operator","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"exists","outputs":[{"name":"_exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"name":"_owner","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"_balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_operator","type":"address"},{"name":"_approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"},{"name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":true,"name":"_tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_approved","type":"address"},{"indexed":true,"name":"_tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_operator","type":"address"},{"indexed":false,"name":"_approved","type":"bool"}],"name":"ApprovalForAll","type":"event"}] diff --git a/abi/ERC721Enumerable.abi b/abi/ERC721Enumerable.abi new file mode 100644 index 0000000..c27d756 --- /dev/null +++ b/abi/ERC721Enumerable.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"name":"_operator","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"name":"_tokenId","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"exists","outputs":[{"name":"_exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"name":"_owner","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"_balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_operator","type":"address"},{"name":"_approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"},{"name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":true,"name":"_tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_approved","type":"address"},{"indexed":true,"name":"_tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_operator","type":"address"},{"indexed":false,"name":"_approved","type":"bool"}],"name":"ApprovalForAll","type":"event"}] diff --git a/abi/ERC721Metadata.abi b/abi/ERC721Metadata.abi new file mode 100644 index 0000000..84b5b78 --- /dev/null +++ b/abi/ERC721Metadata.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"_name","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"name":"_operator","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"exists","outputs":[{"name":"_exists","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"name":"_owner","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"_balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"_symbol","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_operator","type":"address"},{"name":"_approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_tokenId","type":"uint256"},{"name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_from","type":"address"},{"indexed":true,"name":"_to","type":"address"},{"indexed":true,"name":"_tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_approved","type":"address"},{"indexed":true,"name":"_tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_owner","type":"address"},{"indexed":true,"name":"_operator","type":"address"},{"indexed":false,"name":"_approved","type":"bool"}],"name":"ApprovalForAll","type":"event"}] diff --git a/abi/IActivity.abi b/abi/IActivity.abi new file mode 100644 index 0000000..7d93972 --- /dev/null +++ b/abi/IActivity.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"activityStopped","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] diff --git a/abi/IAuthority.abi b/abi/IAuthority.abi new file mode 100644 index 0000000..367dc84 --- /dev/null +++ b/abi/IAuthority.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"src","type":"address"},{"name":"dst","type":"address"},{"name":"sig","type":"bytes4"}],"name":"canCall","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"}] diff --git a/abi/IInterstellarEncoder.abi b/abi/IInterstellarEncoder.abi new file mode 100644 index 0000000..21a524e --- /dev/null +++ b/abi/IInterstellarEncoder.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"_tokenAddress","type":"address"},{"name":"_objectContract","type":"address"},{"name":"_objectId","type":"uint128"}],"name":"encodeTokenIdForObjectContract","outputs":[{"name":"_tokenId","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"MAGIC_NUMBER","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CURRENT_LAND","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenAddress","type":"address"},{"name":"_objectClass","type":"uint8"},{"name":"_objectIndex","type":"uint128"}],"name":"encodeTokenId","outputs":[{"name":"_tokenId","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CHAIN_ID","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"getContractAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"getObjectAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"getObjectId","outputs":[{"name":"_objectId","type":"uint128"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenAddress","type":"address"}],"name":"registerNewTokenContract","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_objectContract","type":"address"},{"name":"objectClass","type":"uint8"}],"name":"registerNewObjectClass","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"getObjectClass","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"}] diff --git a/abi/ILandBase.abi b/abi/ILandBase.abi new file mode 100644 index 0000000..bc2d0c9 --- /dev/null +++ b/abi/ILandBase.abi @@ -0,0 +1 @@ +[{"constant":false,"inputs":[{"name":"_resourceToken","type":"address"},{"name":"_attrId","type":"uint8"}],"name":"defineResouceTokenRateAttrId","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"}],"name":"getFlagMask","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"isReserved","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"}],"name":"getResourceRateAttr","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_newFlagMask","type":"uint256"}],"name":"setFlagMask","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resouceToken","type":"address"}],"name":"getResourceRate","outputs":[{"name":"","type":"uint16"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"isHasBox","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenID","type":"uint256"},{"name":"_resourceToken","type":"address"},{"name":"_newResouceRate","type":"uint16"}],"name":"setResourceRate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenID","type":"uint256"},{"name":"isHasBox","type":"bool"}],"name":"setHasBox","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_newResourceRateAttr","type":"uint256"}],"name":"setResourceRateAttr","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"isSpecial","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"resourceToken","type":"address"},{"indexed":false,"name":"newResourceRate","type":"uint16"}],"name":"ModifiedResourceRate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"hasBox","type":"bool"}],"name":"HasboxSetted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"attr","type":"uint256"}],"name":"ChangedReourceRateAttr","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"newFlagMask","type":"uint256"}],"name":"ChangedFlagMask","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"x","type":"int256"},{"indexed":false,"name":"y","type":"int256"},{"indexed":false,"name":"beneficiary","type":"address"},{"indexed":false,"name":"resourceRateAttr","type":"uint256"},{"indexed":false,"name":"mask","type":"uint256"}],"name":"CreatedNewLand","type":"event"}] diff --git a/abi/ILandBaseExt.abi b/abi/ILandBaseExt.abi new file mode 100644 index 0000000..4a6e9d3 --- /dev/null +++ b/abi/ILandBaseExt.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"_resourceToken","type":"address"}],"name":"resourceToken2RateAttrId","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] diff --git a/abi/IMetaDataTeller.abi b/abi/IMetaDataTeller.abi new file mode 100644 index 0000000..473c438 --- /dev/null +++ b/abi/IMetaDataTeller.abi @@ -0,0 +1 @@ +[{"constant":false,"inputs":[{"name":"_token","type":"address"},{"name":"_grade","type":"uint16"},{"name":"_strengthRate","type":"uint112"}],"name":"addTokenMeta","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_token","type":"address"},{"name":"_id","type":"uint256"},{"name":"_index","type":"uint256"}],"name":"getRate","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_token","type":"address"}],"name":"getPrefer","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_token","type":"address"},{"name":"_id","type":"uint256"}],"name":"getMetaData","outputs":[{"name":"","type":"uint16"},{"name":"","type":"uint16"},{"name":"","type":"uint16"}],"payable":false,"stateMutability":"view","type":"function"}] diff --git a/abi/IMinerObject.abi b/abi/IMinerObject.abi new file mode 100644 index 0000000..d7fb2c9 --- /dev/null +++ b/abi/IMinerObject.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_resourceToken","type":"address"},{"name":"_landTokenId","type":"uint256"}],"name":"strengthOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] diff --git a/abi/IMintableERC20.abi b/abi/IMintableERC20.abi new file mode 100644 index 0000000..37a4fb4 --- /dev/null +++ b/abi/IMintableERC20.abi @@ -0,0 +1 @@ +[{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"mint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] diff --git a/abi/IMysteriousTreasure.abi b/abi/IMysteriousTreasure.abi new file mode 100644 index 0000000..10d5d17 --- /dev/null +++ b/abi/IMysteriousTreasure.abi @@ -0,0 +1 @@ +[{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"unbox","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"}] diff --git a/abi/IObjectOwnership.abi b/abi/IObjectOwnership.abi new file mode 100644 index 0000000..786ea75 --- /dev/null +++ b/abi/IObjectOwnership.abi @@ -0,0 +1 @@ +[{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_objectId","type":"uint128"}],"name":"mintObject","outputs":[{"name":"_tokenId","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_objectId","type":"uint128"}],"name":"burnObject","outputs":[{"name":"_tokenId","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"}] diff --git a/abi/ISettingsRegistry.abi b/abi/ISettingsRegistry.abi new file mode 100644 index 0000000..e231b5a --- /dev/null +++ b/abi/ISettingsRegistry.abi @@ -0,0 +1 @@ +[{"constant":false,"inputs":[{"name":"_propertyName","type":"bytes32"},{"name":"_value","type":"uint256"}],"name":"setUintProperty","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_propertyName","type":"bytes32"}],"name":"bytesOf","outputs":[{"name":"","type":"bytes"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_propertyName","type":"bytes32"}],"name":"uintOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_propertyName","type":"bytes32"},{"name":"_value","type":"bytes"}],"name":"setBytesProperty","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_propertyName","type":"bytes32"},{"name":"_value","type":"bool"}],"name":"setBoolProperty","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_propertyName","type":"bytes32"},{"name":"_value","type":"int256"}],"name":"setIntProperty","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_propertyName","type":"bytes32"}],"name":"intOf","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_propertyName","type":"bytes32"},{"name":"_value","type":"address"}],"name":"setAddressProperty","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_propertyName","type":"bytes32"}],"name":"boolOf","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_propertyName","type":"bytes32"}],"name":"addressOf","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_propertyName","type":"bytes32"}],"name":"stringOf","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_propertyName","type":"bytes32"}],"name":"getValueTypeOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_propertyName","type":"bytes32"},{"name":"_value","type":"string"}],"name":"setStringProperty","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_propertyName","type":"bytes32"},{"indexed":false,"name":"_type","type":"uint256"}],"name":"ChangeProperty","type":"event"}] diff --git a/abi/ITokenLocation.abi b/abi/ITokenLocation.abi new file mode 100644 index 0000000..c50b1d6 --- /dev/null +++ b/abi/ITokenLocation.abi @@ -0,0 +1 @@ +[{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_x","type":"int256"},{"name":"_y","type":"int256"}],"name":"setTokenLocationHM","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"getTokenLocation","outputs":[{"name":"","type":"int256"},{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"getTokenLocationHM","outputs":[{"name":"","type":"int256"},{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"hasLocation","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_x","type":"int256"},{"name":"_y","type":"int256"}],"name":"setTokenLocation","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] diff --git a/abi/ITokenUse.abi b/abi/ITokenUse.abi new file mode 100644 index 0000000..03e2fec --- /dev/null +++ b/abi/ITokenUse.abi @@ -0,0 +1 @@ +[{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_user","type":"address"}],"name":"removeActivity","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"getTokenUser","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"takeTokenUseOffer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"cancelTokenUseOffer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"isObjectInHireStage","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"isObjectReadyToUse","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"MAX_UINT48_TIME","outputs":[{"name":"","type":"uint48"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_duration","type":"uint256"},{"name":"_price","type":"uint256"},{"name":"_acceptedActivity","type":"address"}],"name":"createTokenUseOffer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_user","type":"address"},{"name":"_endTime","type":"uint256"}],"name":"addActivity","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] diff --git a/abi/LandBase.abi b/abi/LandBase.abi new file mode 100644 index 0000000..3c4b7ca --- /dev/null +++ b/abi/LandBase.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[],"name":"CONTRACT_USER_POINTS","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"tokenId2LandAttr","outputs":[{"name":"resourceRateAttr","type":"uint256"},{"name":"mask","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_x","type":"int256"},{"name":"_y","type":"int256"}],"name":"ownerOfLand","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_resourceToken","type":"address"},{"name":"_attrId","type":"uint8"}],"name":"defineResouceTokenRateAttrId","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"UINT_BRIDGE_FEE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_xs","type":"int256[]"},{"name":"_ys","type":"int256[]"}],"name":"ownerOfLandMany","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_BRIDGE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WATER_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"}],"name":"getFlagMask","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenID","type":"uint256"}],"name":"isReserved","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_GOLD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"}],"name":"getResourceRateAttr","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_RING_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_newFlagMask","type":"uint256"}],"name":"setFlagMask","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"UINT_AUCTION_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_x","type":"int256"},{"name":"_y","type":"int256"},{"name":"_beneficiary","type":"address"},{"name":"_resourceRateAttr","type":"uint256"},{"name":"_mask","type":"uint256"}],"name":"assignNewLand","outputs":[{"name":"_tokenId","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_LOCATION","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_KTON_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_x","type":"int256"},{"name":"_y","type":"int256"}],"name":"getTokenIdByLocation","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WOOD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_FIRE_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceToken","type":"address"}],"name":"getResourceRate","outputs":[{"name":"","type":"uint16"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenID","type":"uint256"}],"name":"isHasBox","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"registry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_INTERSTELLAR_ENCODER","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_PET_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceToken","type":"address"},{"name":"_newResouceRate","type":"uint16"}],"name":"setResourceRate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_landholder","type":"address"}],"name":"landOf","outputs":[{"name":"","type":"int256[]"},{"name":"","type":"int256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_SOIL_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenID","type":"uint256"},{"name":"_isHasBox","type":"bool"}],"name":"setHasBox","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_OBJECT_OWNERSHIP","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"resourceToken2RateAttrId","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_x","type":"int256"},{"name":"_y","type":"int256"}],"name":"exists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_USE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_registry","type":"address"}],"name":"initializeContract","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_ERC721_BRIDGE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_REVENUE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"lastLandObjectId","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_newResourceRateAttr","type":"uint256"}],"name":"setResourceRateAttr","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenID","type":"uint256"}],"name":"isSpecial","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_RESOURCE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"locationId2TokenId","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_REFERER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_TOKEN_OFFER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_DIVIDENDS_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_xs","type":"int256[]"},{"name":"_ys","type":"int256[]"},{"name":"_beneficiary","type":"address"},{"name":"_resourceRateAttrs","type":"uint256[]"},{"name":"_masks","type":"uint256[]"}],"name":"assignMultipleLands","outputs":[{"name":"","type":"uint256[]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"resourceToken","type":"address"},{"indexed":false,"name":"newResourceRate","type":"uint16"}],"name":"ModifiedResourceRate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"hasBox","type":"bool"}],"name":"HasboxSetted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"attr","type":"uint256"}],"name":"ChangedReourceRateAttr","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"newFlagMask","type":"uint256"}],"name":"ChangedFlagMask","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"x","type":"int256"},{"indexed":false,"name":"y","type":"int256"},{"indexed":false,"name":"beneficiary","type":"address"},{"indexed":false,"name":"resourceRateAttr","type":"uint256"},{"indexed":false,"name":"mask","type":"uint256"}],"name":"CreatedNewLand","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"}] diff --git a/abi/LandBaseAuthority.abi b/abi/LandBaseAuthority.abi new file mode 100644 index 0000000..75d63a2 --- /dev/null +++ b/abi/LandBaseAuthority.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"whiteList","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_src","type":"address"},{"name":"","type":"address"},{"name":"_sig","type":"bytes4"}],"name":"canCall","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_whitelists","type":"address[]"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}] diff --git a/abi/LandBaseV2.abi b/abi/LandBaseV2.abi new file mode 100644 index 0000000..b1c2740 --- /dev/null +++ b/abi/LandBaseV2.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[],"name":"CONTRACT_USER_POINTS","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"tokenId2LandAttr","outputs":[{"name":"resourceRateAttr","type":"uint256"},{"name":"mask","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_x","type":"int256"},{"name":"_y","type":"int256"}],"name":"ownerOfLand","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_resourceToken","type":"address"},{"name":"_attrId","type":"uint8"}],"name":"defineResouceTokenRateAttrId","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"UINT_BRIDGE_FEE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_xs","type":"int256[]"},{"name":"_ys","type":"int256[]"}],"name":"ownerOfLandMany","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_BRIDGE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WATER_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"}],"name":"getFlagMask","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenID","type":"uint256"}],"name":"isReserved","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_GOLD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"}],"name":"getResourceRateAttr","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_RING_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_newFlagMask","type":"uint256"}],"name":"setFlagMask","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"UINT_AUCTION_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_x","type":"int256"},{"name":"_y","type":"int256"},{"name":"_beneficiary","type":"address"},{"name":"_resourceRateAttr","type":"uint256"},{"name":"_mask","type":"uint256"}],"name":"assignNewLand","outputs":[{"name":"_tokenId","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_LOCATION","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"yHigh","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_KTON_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_x","type":"int256"},{"name":"_y","type":"int256"}],"name":"getTokenIdByLocation","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WOOD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_FIRE_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceToken","type":"address"}],"name":"getResourceRate","outputs":[{"name":"","type":"uint16"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenID","type":"uint256"}],"name":"isHasBox","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"registry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_INTERSTELLAR_ENCODER","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_PET_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceToken","type":"address"},{"name":"_newResouceRate","type":"uint16"}],"name":"setResourceRate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_landholder","type":"address"}],"name":"landOf","outputs":[{"name":"","type":"int256[]"},{"name":"","type":"int256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_SOIL_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenID","type":"uint256"},{"name":"_isHasBox","type":"bool"}],"name":"setHasBox","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_registry","type":"address"},{"name":"_xLow","type":"int256"},{"name":"_xHigh","type":"int256"},{"name":"_yLow","type":"int256"},{"name":"_yHigh","type":"int256"}],"name":"initializeContract","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_OBJECT_OWNERSHIP","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"resourceToken2RateAttrId","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_x","type":"int256"},{"name":"_y","type":"int256"}],"name":"exists","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_USE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"yLow","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_ERC721_BRIDGE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_REVENUE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"lastLandObjectId","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_newResourceRateAttr","type":"uint256"}],"name":"setResourceRateAttr","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenID","type":"uint256"}],"name":"isSpecial","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_RESOURCE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"xHigh","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"locationId2TokenId","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_REFERER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"xLow","outputs":[{"name":"","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_TOKEN_OFFER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_DIVIDENDS_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_xs","type":"int256[]"},{"name":"_ys","type":"int256[]"},{"name":"_beneficiary","type":"address"},{"name":"_resourceRateAttrs","type":"uint256[]"},{"name":"_masks","type":"uint256[]"}],"name":"assignMultipleLands","outputs":[{"name":"","type":"uint256[]"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"resourceToken","type":"address"},{"indexed":false,"name":"newResourceRate","type":"uint16"}],"name":"ModifiedResourceRate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"hasBox","type":"bool"}],"name":"HasboxSetted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"attr","type":"uint256"}],"name":"ChangedReourceRateAttr","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"newFlagMask","type":"uint256"}],"name":"ChangedFlagMask","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"x","type":"int256"},{"indexed":false,"name":"y","type":"int256"},{"indexed":false,"name":"beneficiary","type":"address"},{"indexed":false,"name":"resourceRateAttr","type":"uint256"},{"indexed":false,"name":"mask","type":"uint256"}],"name":"CreatedNewLand","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"}] diff --git a/abi/LandResource.abi b/abi/LandResource.abi new file mode 100644 index 0000000..b8bb0ff --- /dev/null +++ b/abi/LandResource.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_USER_POINTS","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"resourceReleaseStartTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"UINT_BRIDGE_FEE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"InterfaceId_ERC165","outputs":[{"name":"","type":"bytes4"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_BRIDGE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WATER_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_GOLD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_RING_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceTokens","type":"address[5]"}],"name":"availableResources","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"TOTAL_SECONDS","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_AUCTION_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"stopMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_LOCATION","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"}],"name":"mine","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_KTON_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_landTokenId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"startMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WOOD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_FIRE_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"activityStopped","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"miner2Index","outputs":[{"name":"landTokenId","type":"uint256"},{"name":"resource","type":"address"},{"name":"indexInResource","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceToken","type":"address"}],"name":"mintedBalanceOnLand","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceToken","type":"address"}],"name":"getTotalMiningStrength","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"registry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceToken","type":"address"},{"name":"_index","type":"uint256"}],"name":"getMinerOnLand","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_INTERSTELLAR_ENCODER","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_PET_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"attenPerDay","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_SOIL_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_resourceToken","type":"address"},{"name":"_currentTime","type":"uint256"},{"name":"_lastUpdateTime","type":"uint256"}],"name":"_getMinableBalance","outputs":[{"name":"minableBalance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"DENOMINATOR","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"}],"name":"claimAllResource","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_registry","type":"address"},{"name":"_resourceReleaseStartTime","type":"uint256"}],"name":"initializeContract","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_OBJECT_OWNERSHIP","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"land2ResourceMineState","outputs":[{"name":"lastUpdateSpeedInSeconds","type":"uint256"},{"name":"lastDestoryAttenInSeconds","type":"uint256"},{"name":"industryIndex","type":"uint256"},{"name":"lastUpdateTime","type":"uint128"},{"name":"totalMiners","type":"uint64"},{"name":"maxMiners","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_USE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_ERC721_BRIDGE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_REVENUE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenIds","type":"uint256[]"},{"name":"_landTokenIds","type":"uint256[]"},{"name":"_resources","type":"address[]"}],"name":"batchStartMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_RESOURCE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_REFERER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_resourceToken","type":"address"},{"name":"_time","type":"uint256"}],"name":"getReleaseSpeed","outputs":[{"name":"currentSpeed","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"recoverAttenPerDay","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_TOKEN_OFFER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_DIVIDENDS_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"minerTokenId","type":"uint256"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"_resource","type":"address"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"StartMining","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"minerTokenId","type":"uint256"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"_resource","type":"address"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"StopMining","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"goldBalance","type":"uint256"},{"indexed":false,"name":"woodBalance","type":"uint256"},{"indexed":false,"name":"waterBalance","type":"uint256"},{"indexed":false,"name":"fireBalance","type":"uint256"},{"indexed":false,"name":"soilBalance","type":"uint256"}],"name":"ResourceClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"}] diff --git a/abi/LandResourceAuthority.abi b/abi/LandResourceAuthority.abi new file mode 100644 index 0000000..75d63a2 --- /dev/null +++ b/abi/LandResourceAuthority.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"whiteList","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_src","type":"address"},{"name":"","type":"address"},{"name":"_sig","type":"bytes4"}],"name":"canCall","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_whitelists","type":"address[]"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}] diff --git a/abi/LandResourceAuthorityV3.abi b/abi/LandResourceAuthorityV3.abi new file mode 100644 index 0000000..75d63a2 --- /dev/null +++ b/abi/LandResourceAuthorityV3.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"whiteList","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_src","type":"address"},{"name":"","type":"address"},{"name":"_sig","type":"bytes4"}],"name":"canCall","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_whitelists","type":"address[]"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}] diff --git a/abi/LandResourceV2.abi b/abi/LandResourceV2.abi new file mode 100644 index 0000000..b8bb0ff --- /dev/null +++ b/abi/LandResourceV2.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_USER_POINTS","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"resourceReleaseStartTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"UINT_BRIDGE_FEE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"InterfaceId_ERC165","outputs":[{"name":"","type":"bytes4"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_BRIDGE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WATER_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_GOLD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_RING_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceTokens","type":"address[5]"}],"name":"availableResources","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"TOTAL_SECONDS","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_AUCTION_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"stopMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_LOCATION","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"}],"name":"mine","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_KTON_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_landTokenId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"startMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WOOD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_FIRE_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"activityStopped","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"miner2Index","outputs":[{"name":"landTokenId","type":"uint256"},{"name":"resource","type":"address"},{"name":"indexInResource","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceToken","type":"address"}],"name":"mintedBalanceOnLand","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceToken","type":"address"}],"name":"getTotalMiningStrength","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"registry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceToken","type":"address"},{"name":"_index","type":"uint256"}],"name":"getMinerOnLand","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_INTERSTELLAR_ENCODER","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_PET_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"attenPerDay","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_SOIL_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_resourceToken","type":"address"},{"name":"_currentTime","type":"uint256"},{"name":"_lastUpdateTime","type":"uint256"}],"name":"_getMinableBalance","outputs":[{"name":"minableBalance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"DENOMINATOR","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"}],"name":"claimAllResource","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_registry","type":"address"},{"name":"_resourceReleaseStartTime","type":"uint256"}],"name":"initializeContract","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_OBJECT_OWNERSHIP","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"land2ResourceMineState","outputs":[{"name":"lastUpdateSpeedInSeconds","type":"uint256"},{"name":"lastDestoryAttenInSeconds","type":"uint256"},{"name":"industryIndex","type":"uint256"},{"name":"lastUpdateTime","type":"uint128"},{"name":"totalMiners","type":"uint64"},{"name":"maxMiners","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_USE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_ERC721_BRIDGE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_REVENUE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenIds","type":"uint256[]"},{"name":"_landTokenIds","type":"uint256[]"},{"name":"_resources","type":"address[]"}],"name":"batchStartMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_RESOURCE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_REFERER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_resourceToken","type":"address"},{"name":"_time","type":"uint256"}],"name":"getReleaseSpeed","outputs":[{"name":"currentSpeed","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"recoverAttenPerDay","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_TOKEN_OFFER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_DIVIDENDS_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"minerTokenId","type":"uint256"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"_resource","type":"address"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"StartMining","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"minerTokenId","type":"uint256"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"_resource","type":"address"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"StopMining","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"goldBalance","type":"uint256"},{"indexed":false,"name":"woodBalance","type":"uint256"},{"indexed":false,"name":"waterBalance","type":"uint256"},{"indexed":false,"name":"fireBalance","type":"uint256"},{"indexed":false,"name":"soilBalance","type":"uint256"}],"name":"ResourceClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"}] diff --git a/abi/LandResourceV3.abi b/abi/LandResourceV3.abi new file mode 100644 index 0000000..ff87c2c --- /dev/null +++ b/abi/LandResourceV3.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_USER_POINTS","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"resourceReleaseStartTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_apostleTokenId","type":"uint256"}],"name":"updateMinerStrengthWhenStop","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"UINT_BRIDGE_FEE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"InterfaceId_ERC165","outputs":[{"name":"","type":"bytes4"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_BRIDGE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WATER_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_GOLD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_RING_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceTokens","type":"address[5]"}],"name":"availableResources","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"TOTAL_SECONDS","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_AUCTION_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"stopMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_apostleTokenId","type":"uint256"}],"name":"landWorkingOn","outputs":[{"name":"landTokenId","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_LOCATION","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"}],"name":"mine","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_KTON_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_landTokenId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"startMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WOOD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_FIRE_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"activityStopped","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"miner2Index","outputs":[{"name":"landTokenId","type":"uint256"},{"name":"resource","type":"address"},{"name":"indexInResource","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceToken","type":"address"}],"name":"mintedBalanceOnLand","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceToken","type":"address"}],"name":"getTotalMiningStrength","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"registry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceToken","type":"address"},{"name":"_index","type":"uint256"}],"name":"getMinerOnLand","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_INTERSTELLAR_ENCODER","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_PET_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"attenPerDay","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_SOIL_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_resourceToken","type":"address"},{"name":"_currentTime","type":"uint256"},{"name":"_lastUpdateTime","type":"uint256"}],"name":"_getMinableBalance","outputs":[{"name":"minableBalance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_apostleTokenId","type":"uint256"}],"name":"updateMinerStrengthWhenStart","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"DENOMINATOR","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"}],"name":"claimAllResource","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_registry","type":"address"},{"name":"_resourceReleaseStartTime","type":"uint256"}],"name":"initializeContract","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_OBJECT_OWNERSHIP","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"land2ResourceMineState","outputs":[{"name":"lastUpdateSpeedInSeconds","type":"uint256"},{"name":"lastDestoryAttenInSeconds","type":"uint256"},{"name":"industryIndex","type":"uint256"},{"name":"lastUpdateTime","type":"uint128"},{"name":"totalMiners","type":"uint64"},{"name":"maxMiners","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_USE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_ERC721_BRIDGE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_REVENUE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenIds","type":"uint256[]"},{"name":"_landTokenIds","type":"uint256[]"},{"name":"_resources","type":"address[]"}],"name":"batchStartMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_RESOURCE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_REFERER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_resourceToken","type":"address"},{"name":"_time","type":"uint256"}],"name":"getReleaseSpeed","outputs":[{"name":"currentSpeed","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"recoverAttenPerDay","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_TOKEN_OFFER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_DIVIDENDS_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"minerTokenId","type":"uint256"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"_resource","type":"address"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"StartMining","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"minerTokenId","type":"uint256"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"_resource","type":"address"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"StopMining","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"goldBalance","type":"uint256"},{"indexed":false,"name":"woodBalance","type":"uint256"},{"indexed":false,"name":"waterBalance","type":"uint256"},{"indexed":false,"name":"fireBalance","type":"uint256"},{"indexed":false,"name":"soilBalance","type":"uint256"}],"name":"ResourceClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"apostleTokenId","type":"uint256"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"UpdateMiningStrengthWhenStop","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"apostleTokenId","type":"uint256"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"UpdateMiningStrengthWhenStart","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"}] diff --git a/abi/LandResourceV4.abi b/abi/LandResourceV4.abi new file mode 100644 index 0000000..e0164f8 --- /dev/null +++ b/abi/LandResourceV4.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_USER_POINTS","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"resourceReleaseStartTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_apostleTokenId","type":"uint256"}],"name":"updateMinerStrengthWhenStop","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"UINT_BRIDGE_FEE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"InterfaceId_ERC165","outputs":[{"name":"","type":"bytes4"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_BRIDGE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WATER_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_GOLD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_RING_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceTokens","type":"address[5]"}],"name":"availableResources","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"TOTAL_SECONDS","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_AUCTION_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"stopMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_apostleTokenId","type":"uint256"}],"name":"landWorkingOn","outputs":[{"name":"landTokenId","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_LOCATION","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"}],"name":"mine","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_KTON_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_landTokenId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"startMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WOOD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_FIRE_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"activityStopped","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"miner2Index","outputs":[{"name":"landTokenId","type":"uint256"},{"name":"resource","type":"address"},{"name":"indexInResource","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceToken","type":"address"}],"name":"mintedBalanceOnLand","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceToken","type":"address"}],"name":"getTotalMiningStrength","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"registry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landTokenId","type":"uint256"},{"name":"_resourceToken","type":"address"},{"name":"_index","type":"uint256"}],"name":"getMinerOnLand","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_INTERSTELLAR_ENCODER","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_PET_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"attenPerDay","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_SOIL_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_resourceToken","type":"address"},{"name":"_currentTime","type":"uint256"},{"name":"_lastUpdateTime","type":"uint256"}],"name":"_getMinableBalance","outputs":[{"name":"minableBalance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_apostleTokenId","type":"uint256"}],"name":"updateMinerStrengthWhenStart","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"DENOMINATOR","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"}],"name":"claimAllResource","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_registry","type":"address"},{"name":"_resourceReleaseStartTime","type":"uint256"}],"name":"initializeContract","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_OBJECT_OWNERSHIP","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"land2ResourceMineState","outputs":[{"name":"lastUpdateSpeedInSeconds","type":"uint256"},{"name":"lastDestoryAttenInSeconds","type":"uint256"},{"name":"industryIndex","type":"uint256"},{"name":"lastUpdateTime","type":"uint128"},{"name":"totalMiners","type":"uint64"},{"name":"maxMiners","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_USE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenIds","type":"uint256[]"}],"name":"batchClaimAllResource","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_ERC721_BRIDGE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_REVENUE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenIds","type":"uint256[]"},{"name":"_landTokenIds","type":"uint256[]"},{"name":"_resources","type":"address[]"}],"name":"batchStartMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_RESOURCE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_REFERER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_resourceToken","type":"address"},{"name":"_time","type":"uint256"}],"name":"getReleaseSpeed","outputs":[{"name":"currentSpeed","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"recoverAttenPerDay","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_TOKEN_OFFER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_DIVIDENDS_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"minerTokenId","type":"uint256"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"_resource","type":"address"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"StartMining","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"minerTokenId","type":"uint256"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"_resource","type":"address"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"StopMining","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"goldBalance","type":"uint256"},{"indexed":false,"name":"woodBalance","type":"uint256"},{"indexed":false,"name":"waterBalance","type":"uint256"},{"indexed":false,"name":"fireBalance","type":"uint256"},{"indexed":false,"name":"soilBalance","type":"uint256"}],"name":"ResourceClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"apostleTokenId","type":"uint256"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"UpdateMiningStrengthWhenStop","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"apostleTokenId","type":"uint256"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"UpdateMiningStrengthWhenStart","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"}] diff --git a/abi/LandResourceV5.abi b/abi/LandResourceV5.abi new file mode 100644 index 0000000..800898c --- /dev/null +++ b/abi/LandResourceV5.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"getBarsMiningStrength","outputs":[{"name":"barsMiningStrength","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"resourceReleaseStartTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_apostleTokenId","type":"uint256"}],"name":"updateMinerStrengthWhenStop","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_index","type":"uint256"}],"name":"getBarItem","outputs":[{"name":"","type":"address"},{"name":"","type":"uint256"},{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_itemToken","type":"address"},{"name":"_itemId","type":"uint256"}],"name":"claimItemResource","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"InterfaceId_ERC165","outputs":[{"name":"","type":"bytes4"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WATER_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_GOLD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"RATE_PRECISION","outputs":[{"name":"","type":"uint128"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"TOTAL_SECONDS","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_resource","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"enhanceStrengthRateOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenIds","type":"uint256[]"}],"name":"batchClaimLandResource","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"stopMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_apostleTokenId","type":"uint256"}],"name":"landWorkingOn","outputs":[{"name":"landId","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_index","type":"uint256"}],"name":"divest","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resources","type":"address[]"}],"name":"availableLandResources","outputs":[{"name":"","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"}],"name":"mine","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_maxAmount","type":"uint256"}],"name":"setMaxAmount","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"getLandMinedBalance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_item","type":"address"},{"name":"_itemId","type":"uint256"}],"name":"getLandIdByItem","outputs":[{"name":"","type":"address"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_landTokenId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"startMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WOOD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"maxAmount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_FIRE_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"activityStopped","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"miner2Index","outputs":[{"name":"landTokenId","type":"uint256"},{"name":"resource","type":"address"},{"name":"indexInResource","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"getTotalMiningStrength","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"name":"landId2Bars","outputs":[{"name":"staker","type":"address"},{"name":"token","type":"address"},{"name":"id","type":"uint256"},{"name":"resource","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resource","type":"address"},{"name":"_index","type":"uint256"}],"name":"getBarMiningStrength","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"registry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"FURNACE_ITEM_MINE_FEE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resource","type":"address"},{"name":"_index","type":"uint256"}],"name":"getMinerOnLand","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_INTERSTELLAR_ENCODER","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"attenPerDay","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_SOIL_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"protectPeriod","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_resource","type":"address"},{"name":"_index","type":"uint256"},{"name":"_token","type":"address"},{"name":"_id","type":"uint256"}],"name":"equip","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_resource","type":"address"},{"name":"_currentTime","type":"uint256"},{"name":"_lastUpdateTime","type":"uint256"}],"name":"_getMinableBalance","outputs":[{"name":"minableBalance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_apostleTokenId","type":"uint256"}],"name":"updateMinerStrengthWhenStart","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"DENOMINATOR","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_resource","type":"address"},{"name":"_tokenId","type":"uint256"},{"name":"_index","type":"uint256"}],"name":"enhanceStrengthRateByIndex","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_registry","type":"address"},{"name":"_resourceReleaseStartTime","type":"uint256"}],"name":"initializeContract","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_OBJECT_OWNERSHIP","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"land2ResourceMineState","outputs":[{"name":"lastUpdateSpeedInSeconds","type":"uint256"},{"name":"lastDestoryAttenInSeconds","type":"uint256"},{"name":"industryIndex","type":"uint256"},{"name":"lastUpdateTime","type":"uint128"},{"name":"totalMiners","type":"uint64"},{"name":"maxMiners","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_USE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"getBarsRate","outputs":[{"name":"barsRate","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_maxMiners","type":"uint256"}],"name":"setMaxMiners","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_METADATA_TELLER","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenIds","type":"uint256[]"},{"name":"_landTokenIds","type":"uint256[]"},{"name":"_resources","type":"address[]"}],"name":"batchStartMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_itemToken","type":"address"},{"name":"_itemId","type":"uint256"},{"name":"_resources","type":"address[]"}],"name":"availableItemResources","outputs":[{"name":"","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"itemId2Status","outputs":[{"name":"staker","type":"address"},{"name":"tokenId","type":"uint256"},{"name":"index","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_ITEMBAR_PROTECT_PERIOD","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_itemToken","type":"address"},{"name":"_itemId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"getItemMinedBalance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"},{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"land2BarRate","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resource","type":"address"},{"name":"_index","type":"uint256"}],"name":"getBarRate","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"getLandMiningStrength","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_resource","type":"address"},{"name":"_time","type":"uint256"}],"name":"getReleaseSpeed","outputs":[{"name":"currentSpeed","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"recoverAttenPerDay","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landId","type":"uint256"}],"name":"claimLandResource","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_token","type":"address"},{"name":"_id","type":"uint256"}],"name":"isNotProtect","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint256"},{"name":"","type":"address"}],"name":"itemMinedBalance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"minerTokenId","type":"uint256"},{"indexed":false,"name":"landId","type":"uint256"},{"indexed":false,"name":"_resource","type":"address"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"StartMining","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"minerTokenId","type":"uint256"},{"indexed":false,"name":"landId","type":"uint256"},{"indexed":false,"name":"_resource","type":"address"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"StopMining","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"goldBalance","type":"uint256"},{"indexed":false,"name":"woodBalance","type":"uint256"},{"indexed":false,"name":"waterBalance","type":"uint256"},{"indexed":false,"name":"fireBalance","type":"uint256"},{"indexed":false,"name":"soilBalance","type":"uint256"}],"name":"ResourceClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"apostleTokenId","type":"uint256"},{"indexed":false,"name":"landId","type":"uint256"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"UpdateMiningStrengthWhenStop","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"apostleTokenId","type":"uint256"},{"indexed":false,"name":"landId","type":"uint256"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"UpdateMiningStrengthWhenStart","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"barIndex","type":"uint256"},{"indexed":false,"name":"landId","type":"uint256"},{"indexed":false,"name":"resource","type":"address"},{"indexed":false,"name":"rate","type":"uint256"}],"name":"StartBarMining","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"barIndex","type":"uint256"},{"indexed":false,"name":"landId","type":"uint256"},{"indexed":false,"name":"rate","type":"address"}],"name":"StopBarMining","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"landId","type":"uint256"},{"indexed":false,"name":"goldBalance","type":"uint256"},{"indexed":false,"name":"woodBalance","type":"uint256"},{"indexed":false,"name":"waterBalance","type":"uint256"},{"indexed":false,"name":"fireBalance","type":"uint256"},{"indexed":false,"name":"soilBalance","type":"uint256"}],"name":"LandResourceClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"itemToken","type":"address"},{"indexed":false,"name":"itemTokenId","type":"uint256"},{"indexed":false,"name":"goldBalance","type":"uint256"},{"indexed":false,"name":"woodBalance","type":"uint256"},{"indexed":false,"name":"waterBalance","type":"uint256"},{"indexed":false,"name":"fireBalance","type":"uint256"},{"indexed":false,"name":"soilBalance","type":"uint256"}],"name":"ItemResourceClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"resource","type":"address"},{"indexed":false,"name":"index","type":"uint256"},{"indexed":false,"name":"staker","type":"address"},{"indexed":false,"name":"token","type":"address"},{"indexed":false,"name":"id","type":"uint256"}],"name":"Equip","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"resource","type":"address"},{"indexed":false,"name":"index","type":"uint256"},{"indexed":false,"name":"staker","type":"address"},{"indexed":false,"name":"token","type":"address"},{"indexed":false,"name":"id","type":"uint256"}],"name":"Divest","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"}] diff --git a/abi/LandResourceV6.abi b/abi/LandResourceV6.abi new file mode 100644 index 0000000..a831620 --- /dev/null +++ b/abi/LandResourceV6.abi @@ -0,0 +1 @@ +[{"constant":false,"inputs":[{"name":"_itemToken","type":"address"},{"name":"_tokenId","type":"uint256"},{"name":"_index","type":"uint256"}],"name":"devestAndClaim","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"getBarsMiningStrength","outputs":[{"name":"barsMiningStrength","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"resourceReleaseStartTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_apostleTokenId","type":"uint256"}],"name":"updateMinerStrengthWhenStop","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_index","type":"uint256"}],"name":"getBarItem","outputs":[{"name":"","type":"address"},{"name":"","type":"uint256"},{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_itemToken","type":"address"},{"name":"_itemId","type":"uint256"}],"name":"claimItemResource","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"InterfaceId_ERC165","outputs":[{"name":"","type":"bytes4"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WATER_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_GOLD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"RATE_PRECISION","outputs":[{"name":"","type":"uint128"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"TOTAL_SECONDS","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_resource","type":"address"},{"name":"_tokenId","type":"uint256"}],"name":"enhanceStrengthRateOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenIds","type":"uint256[]"}],"name":"batchClaimLandResource","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"stopMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_apostleTokenId","type":"uint256"}],"name":"landWorkingOn","outputs":[{"name":"landId","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_index","type":"uint256"}],"name":"divest","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resources","type":"address[]"}],"name":"availableLandResources","outputs":[{"name":"","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landTokenId","type":"uint256"}],"name":"mine","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_maxAmount","type":"uint256"}],"name":"setMaxAmount","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_itemTokens","type":"address[]"},{"name":"_itemIds","type":"uint256[]"}],"name":"batchClaimItemResource","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"getLandMinedBalance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_item","type":"address"},{"name":"_itemId","type":"uint256"}],"name":"getLandIdByItem","outputs":[{"name":"","type":"address"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_landTokenId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"startMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WOOD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"maxAmount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_FIRE_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"activityStopped","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"miner2Index","outputs":[{"name":"landTokenId","type":"uint256"},{"name":"resource","type":"address"},{"name":"indexInResource","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"getTotalMiningStrength","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"name":"landId2Bars","outputs":[{"name":"staker","type":"address"},{"name":"token","type":"address"},{"name":"id","type":"uint256"},{"name":"resource","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resource","type":"address"},{"name":"_index","type":"uint256"}],"name":"getBarMiningStrength","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"registry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"FURNACE_ITEM_MINE_FEE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resource","type":"address"},{"name":"_index","type":"uint256"}],"name":"getMinerOnLand","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_INTERSTELLAR_ENCODER","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"attenPerDay","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_SOIL_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"protectPeriod","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_resource","type":"address"},{"name":"_index","type":"uint256"},{"name":"_token","type":"address"},{"name":"_id","type":"uint256"}],"name":"equip","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_resource","type":"address"},{"name":"_currentTime","type":"uint256"},{"name":"_lastUpdateTime","type":"uint256"}],"name":"_getMinableBalance","outputs":[{"name":"minableBalance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_apostleTokenId","type":"uint256"}],"name":"updateMinerStrengthWhenStart","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"DENOMINATOR","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_resource","type":"address"},{"name":"_tokenId","type":"uint256"},{"name":"_index","type":"uint256"}],"name":"enhanceStrengthRateByIndex","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_registry","type":"address"},{"name":"_resourceReleaseStartTime","type":"uint256"}],"name":"initializeContract","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_OBJECT_OWNERSHIP","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"land2ResourceMineState","outputs":[{"name":"lastUpdateSpeedInSeconds","type":"uint256"},{"name":"lastDestoryAttenInSeconds","type":"uint256"},{"name":"industryIndex","type":"uint256"},{"name":"lastUpdateTime","type":"uint128"},{"name":"totalMiners","type":"uint64"},{"name":"maxMiners","type":"uint64"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_USE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"getBarsRate","outputs":[{"name":"barsRate","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_maxMiners","type":"uint256"}],"name":"setMaxMiners","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_METADATA_TELLER","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenIds","type":"uint256[]"},{"name":"_landTokenIds","type":"uint256[]"},{"name":"_resources","type":"address[]"}],"name":"batchStartMining","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_itemToken","type":"address"},{"name":"_itemId","type":"uint256"},{"name":"_resources","type":"address[]"}],"name":"availableItemResources","outputs":[{"name":"","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"itemId2Status","outputs":[{"name":"staker","type":"address"},{"name":"tokenId","type":"uint256"},{"name":"index","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_ITEMBAR_PROTECT_PERIOD","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_itemToken","type":"address"},{"name":"_itemId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"getItemMinedBalance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"},{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"land2BarRate","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"maxMiners","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resource","type":"address"},{"name":"_index","type":"uint256"}],"name":"getBarRate","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_landId","type":"uint256"},{"name":"_resource","type":"address"}],"name":"getLandMiningStrength","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_tokenId","type":"uint256"},{"name":"_resource","type":"address"},{"name":"_time","type":"uint256"}],"name":"getReleaseSpeed","outputs":[{"name":"currentSpeed","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"recoverAttenPerDay","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_landId","type":"uint256"}],"name":"claimLandResource","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_token","type":"address"},{"name":"_id","type":"uint256"}],"name":"isNotProtect","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint256"},{"name":"","type":"address"}],"name":"itemMinedBalance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"minerTokenId","type":"uint256"},{"indexed":false,"name":"landId","type":"uint256"},{"indexed":false,"name":"_resource","type":"address"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"StartMining","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"minerTokenId","type":"uint256"},{"indexed":false,"name":"landId","type":"uint256"},{"indexed":false,"name":"_resource","type":"address"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"StopMining","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"landTokenId","type":"uint256"},{"indexed":false,"name":"goldBalance","type":"uint256"},{"indexed":false,"name":"woodBalance","type":"uint256"},{"indexed":false,"name":"waterBalance","type":"uint256"},{"indexed":false,"name":"fireBalance","type":"uint256"},{"indexed":false,"name":"soilBalance","type":"uint256"}],"name":"ResourceClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"apostleTokenId","type":"uint256"},{"indexed":false,"name":"landId","type":"uint256"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"UpdateMiningStrengthWhenStop","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"apostleTokenId","type":"uint256"},{"indexed":false,"name":"landId","type":"uint256"},{"indexed":false,"name":"strength","type":"uint256"}],"name":"UpdateMiningStrengthWhenStart","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"barIndex","type":"uint256"},{"indexed":false,"name":"landId","type":"uint256"},{"indexed":false,"name":"resource","type":"address"},{"indexed":false,"name":"rate","type":"uint256"}],"name":"StartBarMining","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"barIndex","type":"uint256"},{"indexed":false,"name":"landId","type":"uint256"},{"indexed":false,"name":"rate","type":"address"}],"name":"StopBarMining","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"landId","type":"uint256"},{"indexed":false,"name":"goldBalance","type":"uint256"},{"indexed":false,"name":"woodBalance","type":"uint256"},{"indexed":false,"name":"waterBalance","type":"uint256"},{"indexed":false,"name":"fireBalance","type":"uint256"},{"indexed":false,"name":"soilBalance","type":"uint256"}],"name":"LandResourceClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"itemToken","type":"address"},{"indexed":false,"name":"itemTokenId","type":"uint256"},{"indexed":false,"name":"goldBalance","type":"uint256"},{"indexed":false,"name":"woodBalance","type":"uint256"},{"indexed":false,"name":"waterBalance","type":"uint256"},{"indexed":false,"name":"fireBalance","type":"uint256"},{"indexed":false,"name":"soilBalance","type":"uint256"}],"name":"ItemResourceClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"resource","type":"address"},{"indexed":false,"name":"index","type":"uint256"},{"indexed":false,"name":"staker","type":"address"},{"indexed":false,"name":"token","type":"address"},{"indexed":false,"name":"id","type":"uint256"}],"name":"Equip","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"resource","type":"address"},{"indexed":false,"name":"index","type":"uint256"},{"indexed":false,"name":"staker","type":"address"},{"indexed":false,"name":"token","type":"address"},{"indexed":false,"name":"id","type":"uint256"}],"name":"Divest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"maxAmount","type":"uint256"}],"name":"SetMaxLandBar","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"maxMiners","type":"uint256"}],"name":"SetMaxMiner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"}] diff --git a/abi/LandSettingIds.abi b/abi/LandSettingIds.abi new file mode 100644 index 0000000..76a4475 --- /dev/null +++ b/abi/LandSettingIds.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[],"name":"CONTRACT_USER_POINTS","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_BRIDGE_FEE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_BRIDGE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WATER_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_GOLD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_RING_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_AUCTION_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_LOCATION","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_KTON_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WOOD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_FIRE_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_INTERSTELLAR_ENCODER","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_PET_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_SOIL_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_OBJECT_OWNERSHIP","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_USE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_ERC721_BRIDGE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_REVENUE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_RESOURCE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_REFERER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_TOKEN_OFFER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_DIVIDENDS_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"}] diff --git a/abi/LocationCoder.abi b/abi/LocationCoder.abi new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/abi/LocationCoder.abi @@ -0,0 +1 @@ +[] diff --git a/abi/MysteriousTreasure.abi b/abi/MysteriousTreasure.abi new file mode 100644 index 0000000..b217593 --- /dev/null +++ b/abi/MysteriousTreasure.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[],"name":"CONTRACT_USER_POINTS","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"owner_","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"UINT_BRIDGE_FEE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_BRIDGE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_tokenId","type":"uint256"}],"name":"unbox","outputs":[{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"},{"name":"","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WATER_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_GOLD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_RING_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_AUCTION_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalBoxNotOpened","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_LOCATION","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_KTON_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WOOD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_FIRE_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_keyNumber","type":"uint256"},{"name":"_resources","type":"uint256"}],"name":"setResourcePool","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"authority_","type":"address"}],"name":"setAuthority","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"registry","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_INTERSTELLAR_ENCODER","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_PET_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_SOIL_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_OBJECT_OWNERSHIP","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_USE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_ERC721_BRIDGE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_REVENUE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"authority","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_RESOURCE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_REFERER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_registry","type":"address"},{"name":"_resources","type":"uint256[5]"}],"name":"initializeContract","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"UINT_TOKEN_OFFER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"resourcePool","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_DIVIDENDS_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_totalBox","type":"uint256"}],"name":"setTotalBoxNotOpened","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"tokenId","type":"uint256"},{"indexed":false,"name":"goldRate","type":"uint256"},{"indexed":false,"name":"woodRate","type":"uint256"},{"indexed":false,"name":"waterRate","type":"uint256"},{"indexed":false,"name":"fireRate","type":"uint256"},{"indexed":false,"name":"soilRate","type":"uint256"}],"name":"Unbox","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"authority","type":"address"}],"name":"LogSetAuthority","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"}],"name":"LogSetOwner","type":"event"}] diff --git a/abi/MysteriousTreasureAuthority.abi b/abi/MysteriousTreasureAuthority.abi new file mode 100644 index 0000000..8b65413 --- /dev/null +++ b/abi/MysteriousTreasureAuthority.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"whiteList","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_src","type":"address"},{"name":"","type":"address"},{"name":"","type":"bytes4"}],"name":"canCall","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_whitelists","type":"address[]"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}] diff --git a/abi/SafeMath.abi b/abi/SafeMath.abi new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/abi/SafeMath.abi @@ -0,0 +1 @@ +[] diff --git a/abi/SettingIds.abi b/abi/SettingIds.abi new file mode 100644 index 0000000..76a4475 --- /dev/null +++ b/abi/SettingIds.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[],"name":"CONTRACT_USER_POINTS","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_BRIDGE_FEE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_BRIDGE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WATER_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_GOLD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_RING_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_AUCTION_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_LOCATION","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_KTON_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_WOOD_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_FIRE_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_INTERSTELLAR_ENCODER","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_PET_BASE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_SOIL_ERC20_TOKEN","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_OBJECT_OWNERSHIP","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_TOKEN_USE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_ERC721_BRIDGE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_REVENUE_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_LAND_RESOURCE","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_REFERER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"UINT_TOKEN_OFFER_CUT","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"CONTRACT_DIVIDENDS_POOL","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"}] diff --git a/abi/SupportsInterfaceWithLookup.abi b/abi/SupportsInterfaceWithLookup.abi new file mode 100644 index 0000000..ed3fed4 --- /dev/null +++ b/abi/SupportsInterfaceWithLookup.abi @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"_interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"InterfaceId_ERC165","outputs":[{"name":"","type":"bytes4"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}] From 9530e6b8867075c0cd8e83abb478fee91043d693 Mon Sep 17 00:00:00 2001 From: echo Date: Fri, 24 Sep 2021 10:38:07 +0800 Subject: [PATCH 31/32] renter can stop mine & fix equip none land --- contracts/LandResourceV6.sol | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/contracts/LandResourceV6.sol b/contracts/LandResourceV6.sol index 9a6d985..084477c 100644 --- a/contracts/LandResourceV6.sol +++ b/contracts/LandResourceV6.sol @@ -703,13 +703,13 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { function stopMining(uint256 _tokenId) public { address ownership = registry.addressOf(CONTRACT_OBJECT_OWNERSHIP); address tokenuse = registry.addressOf(CONTRACT_TOKEN_USE); - if (ERC721(ownership).ownerOf(_tokenId) == msg.sender) { + address user = ITokenUse(tokenuse).getTokenUser(_tokenId); + if (ERC721(ownership).ownerOf(_tokenId) == msg.sender || user == msg.sender) { ITokenUse(tokenuse).removeActivity(_tokenId, msg.sender); } else { // Land owner has right to stop mining uint256 landTokenId = miner2Index[_tokenId].landTokenId; require(msg.sender == ERC721(ownership).ownerOf(landTokenId), "Land: ONLY_LANDER"); - address user = ITokenUse(tokenuse).getTokenUser(_tokenId); ITokenUse(tokenuse).removeActivity(_tokenId, user); } } @@ -1303,8 +1303,9 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER) ) .getObjectClass(_tokenId) == 1, - "Funace: ONLY_LAND" + "Furnace: ONLY_LAND" ); + require(ERC721(registry.addressOf(CONTRACT_OBJECT_OWNERSHIP)).exists(_tokenId), "Furnace: NOT_EXIST"); (uint16 objClassExt, uint16 class, uint16 grade) = teller.getMetaData(_token, _id); require(objClassExt > 0, "Furnace: PERMISSION"); From 605a90fc3c5c0a19903d43d1ac892a949554c408 Mon Sep 17 00:00:00 2001 From: echo Date: Fri, 24 Sep 2021 11:29:15 +0800 Subject: [PATCH 32/32] rm dead code --- contracts/LandResourceV6.sol | 323 +++++++---------------------------- 1 file changed, 66 insertions(+), 257 deletions(-) diff --git a/contracts/LandResourceV6.sol b/contracts/LandResourceV6.sol index 084477c..90595b3 100644 --- a/contracts/LandResourceV6.sol +++ b/contracts/LandResourceV6.sol @@ -238,8 +238,8 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { singletonLock = true; } - // initializeContract be called by proxy contract - // see https://blog.openzeppelin.com/the-transparent-proxy-pattern/ + // initializeContract be called by proxy contract + // see https://blog.openzeppelin.com/the-transparent-proxy-pattern/ function initializeContract( address _registry, uint256 _resourceReleaseStartTime @@ -253,11 +253,11 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { resourceReleaseStartTime = _resourceReleaseStartTime; - //see https://github.com/evolutionlandorg/common-contracts/blob/2873a4f8f970bd442ffcf9c6ae63b3dc79e743db/contracts/interfaces/IActivity.sol#L6 + //see https://github.com/evolutionlandorg/common-contracts/blob/2873a4f8f970bd442ffcf9c6ae63b3dc79e743db/contracts/interfaces/IActivity.sol#L6 _registerInterface(InterfaceId_IActivity); - maxMiners = 5; - maxAmount = 5; + maxMiners = 5; + maxAmount = 5; } // get amount of speed uint at this moment @@ -283,32 +283,6 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { uint256 availableSpeedInSeconds = TOTAL_SECONDS.sub(_time - resourceReleaseStartTime); return availableSpeedInSeconds; - // // time from last update - // uint256 timeBetween = - // _time - land2ResourceMineState[_tokenId].lastUpdateTime; - - // // the recover speed is 20/10000, 20 times. - // // recoveryRate overall from lasUpdateTime til now + amount of speed uint at lastUpdateTime - // uint256 nextSpeedInSeconds = - // land2ResourceMineState[_tokenId].lastUpdateSpeedInSeconds + - // timeBetween * - // recoverAttenPerDay; - // // destroyRate overall from lasUpdateTime til now amount of speed uint at lastUpdateTime - // uint256 destroyedSpeedInSeconds = - // timeBetween * - // land2ResourceMineState[_tokenId].lastDestoryAttenInSeconds; - - // if (nextSpeedInSeconds < destroyedSpeedInSeconds) { - // nextSpeedInSeconds = 0; - // } else { - // nextSpeedInSeconds = nextSpeedInSeconds - destroyedSpeedInSeconds; - // } - - // if (nextSpeedInSeconds > availableSpeedInSeconds) { - // nextSpeedInSeconds = availableSpeedInSeconds; - // } - - // return nextSpeedInSeconds; } function getReleaseSpeed( @@ -326,8 +300,8 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { // For every seconds, the speed will decrease by current speed multiplying (DENOMINATOR_in_seconds - seconds) / DENOMINATOR_in_seconds. // resource will decrease 1/10000 every day. - // `minableBalance` is an area of a trapezoid. - // The reason for dividing by `1 days` twice is that the definition of `getResourceRate` is the number of mines that can be mined per day. + // `minableBalance` is an area of a trapezoid. + // The reason for dividing by `1 days` twice is that the definition of `getResourceRate` is the number of mines that can be mined per day. function _getMinableBalance( uint256 _tokenId, address _resource, @@ -399,28 +373,12 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { "Token must be land." ); - // v5 remove - // if (land2ResourceMineState[_landTokenId].lastUpdateTime == 0) { - // land2ResourceMineState[_landTokenId].lastUpdateTime = uint128( - // resourceReleaseStartTime - // ); - // land2ResourceMineState[_landTokenId] - // .lastUpdateSpeedInSeconds = TOTAL_SECONDS; - // } - _mineResource(_landTokenId, _gold); _mineResource(_landTokenId, _wood); _mineResource(_landTokenId, _water); _mineResource(_landTokenId, _fire); _mineResource(_landTokenId, _soil); - // v5 remove - // land2ResourceMineState[_landTokenId] - // .lastUpdateSpeedInSeconds = _getReleaseSpeedInSeconds( - // _landTokenId, - // now - // ); - land2ResourceMineState[_landTokenId].lastUpdateTime = uint128(now); } @@ -534,72 +492,6 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { return minedBalance; } - // v5 remove - // function claimAllResource(uint256 _landTokenId) public { - // require( - // msg.sender == ownership.ownerOf(_landTokenId), - // "Must be the owner of the land" - // ); - - // _mineAllResource(_landTokenId, gold, wood, water, fire, soil); - - // uint256 goldBalance; - // uint256 woodBalance; - // uint256 waterBalance; - // uint256 fireBalance; - // uint256 soilBalance; - - // if (land2ResourceMineState[_landTokenId].mintedBalance[gold] > 0) { - // goldBalance = land2ResourceMineState[_landTokenId].mintedBalance[ - // gold - // ]; - // IMintableERC20(gold).mint(msg.sender, goldBalance); - // land2ResourceMineState[_landTokenId].mintedBalance[gold] = 0; - // } - - // if (land2ResourceMineState[_landTokenId].mintedBalance[wood] > 0) { - // woodBalance = land2ResourceMineState[_landTokenId].mintedBalance[ - // wood - // ]; - // IMintableERC20(wood).mint(msg.sender, woodBalance); - // land2ResourceMineState[_landTokenId].mintedBalance[wood] = 0; - // } - - // if (land2ResourceMineState[_landTokenId].mintedBalance[water] > 0) { - // waterBalance = land2ResourceMineState[_landTokenId].mintedBalance[ - // water - // ]; - // IMintableERC20(water).mint(msg.sender, waterBalance); - // land2ResourceMineState[_landTokenId].mintedBalance[water] = 0; - // } - - // if (land2ResourceMineState[_landTokenId].mintedBalance[fire] > 0) { - // fireBalance = land2ResourceMineState[_landTokenId].mintedBalance[ - // fire - // ]; - // IMintableERC20(fire).mint(msg.sender, fireBalance); - // land2ResourceMineState[_landTokenId].mintedBalance[fire] = 0; - // } - - // if (land2ResourceMineState[_landTokenId].mintedBalance[soil] > 0) { - // soilBalance = land2ResourceMineState[_landTokenId].mintedBalance[ - // soil - // ]; - // IMintableERC20(soil).mint(msg.sender, soilBalance); - // land2ResourceMineState[_landTokenId].mintedBalance[soil] = 0; - // } - - // emit ResourceClaimed( - // msg.sender, - // _landTokenId, - // goldBalance, - // woodBalance, - // waterBalance, - // fireBalance, - // soilBalance - // ); - // } - // both for own _tokenId or hired one function startMining( uint256 _tokenId, @@ -632,11 +524,6 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { land2ResourceMineState[_landTokenId].totalMiners += 1; - // v5 remove - // if (land2ResourceMineState[_landTokenId].maxMiners == 0) { - // land2ResourceMineState[_landTokenId].maxMiners = 5; - // } - require( land2ResourceMineState[_landTokenId].totalMiners <= maxMiners, "Land: EXCEED_MAXAMOUNT" @@ -789,150 +676,72 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { emit StopMining(_tokenId, landTokenId, resource, strength); } - // v5 remove - // function getMinerOnLand( - // uint256 _landTokenId, - // address _resourceToken, - // uint256 _index - // ) public view returns (uint256) { - // return - // land2ResourceMineState[_landTokenId].miners[_resourceToken][_index]; - // } + // function _updateMinerStrength(uint256 _apostleTokenId, bool _isStop) + // internal + // returns (uint256, uint256) + // { + // // require that this apostle + // uint256 landTokenId = landWorkingOn(_apostleTokenId); + // require(landTokenId != 0, "this apostle is not mining."); + + // address resource = miner2Index[_apostleTokenId].resource; + + // address miner = + // IInterstellarEncoder( + // registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER) + // ) + // .getObjectAddress(_apostleTokenId); + // uint256 strength = + // IMinerObject(miner).strengthOf( + // _apostleTokenId, + // resource, + // landTokenId + // ); + + // mine(landTokenId); + + // if (_isStop) { + // land2ResourceMineState[landTokenId].totalMinerStrength[ + // resource + // ] = land2ResourceMineState[landTokenId].totalMinerStrength[resource] + // .sub(strength); + // } else { + // land2ResourceMineState[landTokenId].totalMinerStrength[resource] = land2ResourceMineState[landTokenId].totalMinerStrength[resource].add(strength); + // } - // function getTotalMiningStrength( - // uint256 _landTokenId, - // address _resourceToken - // ) public view returns (uint256) { - // return - // land2ResourceMineState[_landTokenId].totalMinerStrength[ - // _resourceToken - // ]; + // return (landTokenId, strength); // } - // function availableResources( - // uint256 _landTokenId, - // address[5] _resourceTokens - // ) - // public - // view - // returns ( - // uint256, - // uint256, - // uint256, - // uint256, - // uint256 - // ) - // { - // uint256 availableGold = - // _calculateMinedBalance(_landTokenId, _resourceTokens[0], now) + - // land2ResourceMineState[_landTokenId].mintedBalance[ - // _resourceTokens[0] - // ]; - // uint256 availableWood = - // _calculateMinedBalance(_landTokenId, _resourceTokens[1], now) + - // land2ResourceMineState[_landTokenId].mintedBalance[ - // _resourceTokens[1] - // ]; - // uint256 availableWater = - // _calculateMinedBalance(_landTokenId, _resourceTokens[2], now) + - // land2ResourceMineState[_landTokenId].mintedBalance[ - // _resourceTokens[2] - // ]; - // uint256 availableFire = - // _calculateMinedBalance(_landTokenId, _resourceTokens[3], now) + - // land2ResourceMineState[_landTokenId].mintedBalance[ - // _resourceTokens[3] - // ]; - // uint256 availableSoil = - // _calculateMinedBalance(_landTokenId, _resourceTokens[4], now) + - // land2ResourceMineState[_landTokenId].mintedBalance[ - // _resourceTokens[4] - // ]; - - // return ( - // availableGold, - // availableWood, - // availableWater, - // availableFire, - // availableSoil + // // when a mirrorToken or a pet has tied to apostle + // // we need to update status and remove this apostle from mining list first + // // open authority to PetBase + // // can only be called by PetBase + // function updateMinerStrengthWhenStop(uint256 _apostleTokenId) public auth { + // uint256 landTokenId; + // uint256 strength; + // (landTokenId, strength) = _updateMinerStrength(_apostleTokenId, true); + // // _isStop == true - minus strength + // // _isStop == false - add strength + // emit UpdateMiningStrengthWhenStop( + // _apostleTokenId, + // landTokenId, + // strength // ); // } - // V5 remove - // function mintedBalanceOnLand(uint256 _landTokenId, address _resourceToken) public view returns (uint256) { - // return land2ResourceMineState[_landTokenId].mintedBalance[_resourceToken]; - // } - - // function landWorkingOn(uint256 _apostleTokenId) public view returns (uint256 landTokenId) { - // landTokenId = miner2Index[_apostleTokenId].landTokenId; + // function updateMinerStrengthWhenStart(uint256 _apostleTokenId) public auth { + // uint256 landTokenId; + // uint256 strength; + // (landTokenId, strength) = _updateMinerStrength(_apostleTokenId, false); + // // _isStop == true - minus strength + // // _isStop == false - add strength + // emit UpdateMiningStrengthWhenStart( + // _apostleTokenId, + // landTokenId, + // strength + // ); // } - function _updateMinerStrength(uint256 _apostleTokenId, bool _isStop) - internal - returns (uint256, uint256) - { - // require that this apostle - uint256 landTokenId = landWorkingOn(_apostleTokenId); - require(landTokenId != 0, "this apostle is not mining."); - - address resource = miner2Index[_apostleTokenId].resource; - - address miner = - IInterstellarEncoder( - registry.addressOf(CONTRACT_INTERSTELLAR_ENCODER) - ) - .getObjectAddress(_apostleTokenId); - uint256 strength = - IMinerObject(miner).strengthOf( - _apostleTokenId, - resource, - landTokenId - ); - - mine(landTokenId); - - if (_isStop) { - land2ResourceMineState[landTokenId].totalMinerStrength[ - resource - ] = land2ResourceMineState[landTokenId].totalMinerStrength[resource] - .sub(strength); - } else { - land2ResourceMineState[landTokenId].totalMinerStrength[resource] = land2ResourceMineState[landTokenId].totalMinerStrength[resource].add(strength); - } - - return (landTokenId, strength); - } - - // when a mirrorToken or a pet has tied to apostle - // we need to update status and remove this apostle from mining list first - // open authority to PetBase - // can only be called by PetBase - function updateMinerStrengthWhenStop(uint256 _apostleTokenId) public auth { - uint256 landTokenId; - uint256 strength; - (landTokenId, strength) = _updateMinerStrength(_apostleTokenId, true); - // _isStop == true - minus strength - // _isStop == false - add strength - emit UpdateMiningStrengthWhenStop( - _apostleTokenId, - landTokenId, - strength - ); - } - - function updateMinerStrengthWhenStart(uint256 _apostleTokenId) public auth { - uint256 landTokenId; - uint256 strength; - (landTokenId, strength) = _updateMinerStrength(_apostleTokenId, false); - // _isStop == true - minus strength - // _isStop == false - add strength - emit UpdateMiningStrengthWhenStart( - _apostleTokenId, - landTokenId, - strength - ); - } - // V5 add function getLandMinedBalance(uint256 _landId, address _resource) public @@ -1325,7 +1134,7 @@ contract LandResourceV6 is SupportsInterfaceWithLookup, DSAuth, IActivity { ); //TODO:: safe transfer ERC721(bar.token).transferFrom(address(this), bar.staker, bar.id); - delete itemId2Status[bar.staker][bar.id]; + delete itemId2Status[bar.staker][bar.id]; // emit Divest( // _tokenId, // bar.resource,