Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions contracts/lands/LandClaimer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ contract LandClaimer is Ownable, ContextMixin {
_properties.resource4,
_properties.resourceLevel1,
_properties.resourceLevel2,
_properties.resourceLevel3,
_properties.resourceLevel4
_properties.resourceLevel3
);

bytes32 _hash = keccak256(props);
Expand Down
4 changes: 2 additions & 2 deletions contracts/lands/LandERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract LandERC721 is ERC721TradableMixin {
uint8 resourceLevel1;
uint8 resourceLevel2;
uint8 resourceLevel3;
uint8 resourceLevel4;
// uint8 resourceLevel4;
}

event PropertiesUpdated(uint256 indexed _tokenId, Properties _props);
Expand All @@ -46,7 +46,7 @@ contract LandERC721 is ERC721TradableMixin {
_properties.resourceLevel1 = 10;
_properties.resourceLevel2 = 10;
_properties.resourceLevel3 = 10;
_properties.resourceLevel4 = 10;
// _properties.resourceLevel4 = 10;
_setProperties(0, _properties);
_mint(_genesisReceiver, 0);
}
Expand Down
130 changes: 130 additions & 0 deletions contracts/modules/RawResourceMinter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import { LandERC721 } from "../lands/LandERC721.sol";
import { WinzerERC721 } from "../winzers/WinzerERC721.sol";
import { ResourcesERC1155 } from "../resources/ResourcesERC1155.sol";

contract RawResourceMinter is Ownable {

using SafeMath for uint256;

struct Works {
uint256 winzerId;
uint256 landId;
// @dev 0 = resource1, 1 = resource2, 2 = resource3, 3 = resource4
uint8 landZone;
// @dev timestamp of when winzer started work
uint256 startedAt;
// @dev timestamp of when owner claimed resources last time
uint256 claimedAt;
bool enabled;
address owner;
}

struct ResourceData {
// @dev land resource deposit id to raw resource id
uint256 resourceID;
// @dev land resource deposit id to time in seconds required to mint one resource
uint256 requiredTime;
}

event WorkStarted(bytes32 indexed _zone, Works _work);
event WorkStoped(bytes32 indexed _zone);
event ResourcesClaimed(bytes32 indexed _zone, uint256 _resourceId, uint256 _amount);
event ResourceDataUpdated(uint8 indexed _depositId, ResourceData _data);

mapping(bytes32 => Works) public workspace;
mapping(uint8 => ResourceData) public resources;

LandERC721 public landContract;
WinzerERC721 public winzerContract;
ResourcesERC1155 public resourceContract;

constructor (address _land, address _winzer, address _resource) {
landContract = LandERC721(_land);
winzerContract = WinzerERC721(_winzer);
resourceContract = ResourcesERC1155(_resource);
}

function updateResourceData(uint8 _depositId, ResourceData calldata _data) public onlyOwner {
resources[_depositId] = _data;
emit ResourceDataUpdated(_depositId, _data);
}

function assign(uint256 _winzerId, uint256 _landId, uint8 _landZone) public returns (bytes32) {
bytes32 zone = keccak256(abi.encode(_landId, _landZone));
(uint8 resource,) = getResource(_landId, _landZone);
require(resource != 0, "land has no resource.");
require(workspace[zone].startedAt == 0, "Already working.");
require(winzerContract.ownerOf(_winzerId) == _msgSender(), "You must be owner of winzer.");
require(landContract.ownerOf(_landId) == _msgSender(), "You must be owner of land.");

winzerContract.safeTransferFrom(_msgSender(), address(this), _winzerId);

Works memory _work;
_work.owner = _msgSender();
_work.winzerId = _winzerId;
_work.landId = _landId;
_work.landZone = _landZone;
_work.startedAt = block.timestamp;
_work.claimedAt = block.timestamp;

workspace[zone] = _work;

emit WorkStarted(zone, _work);

return zone;
}

function stop(bytes32 _zone) public {
claim(_zone);

workspace[_zone].startedAt = 0;
workspace[_zone].enabled = false;

emit WorkStoped(_zone);

landContract.safeTransferFrom(address(this), workspace[_zone].owner, workspace[_zone].winzerId);
}

function claim(bytes32 _zone) public {
Works memory work = workspace[_zone];
require(work.startedAt != 0);
require(work.owner == _msgSender());

(uint8 resource, uint8 level) = getResource(work.landId, work.landZone);

require(resource != 0, "land has no resource.");

uint256 amount = calculateAmount(work.claimedAt, block.timestamp, resources[resource].requiredTime);

if (amount > 0) {
work.claimedAt = block.timestamp;
resourceContract.mint(work.owner, resources[resource].resourceID, amount);
}

emit ResourcesClaimed(_zone, resource, amount);
}

function calculateAmount(uint256 _start, uint256 _end, uint256 _time) public pure returns (uint256) {
uint256 diff = _end - _start;
return diff / _time;
}

function getResource(uint256 _landId, uint256 _landZone) public view returns (uint8, uint8) {
(,,,, uint8 resource1, uint8 resource2, uint8 resource3, uint8 resource4, uint8 resourceLevel1, uint8 resourceLevel2, uint8 resourceLevel3) = landContract.properties(_landId);
if (_landZone == 0) {
return (resource1, resourceLevel1);
} else if (_landZone == 1) {
return (resource1, resourceLevel2);
} else if (_landZone == 2) {
return (resource3, resourceLevel3);
} else if (_landZone == 3) {
return (resource4, resourceLevel3);
}
return (0, 0);
}
}
96 changes: 96 additions & 0 deletions contracts/nfts/Winzer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "../mixins/ERC721TradableMixin.sol";

contract WinzerERC721 is ERC721TradableMixin {

bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");

struct DNA1 {
uint8 race;
uint8 sex;
uint8 skin;
uint8 head;
uint8 ears;
uint8 hair;
uint8 beard;
uint8 mouth;
uint8 eyes;
uint8 eyebrows;
uint8 nose;
// uint8 scars;
}

struct DNA2 {
uint256 father;
uint256 mother;
uint8 accessory;
uint8 makeup;
uint8 skill1;
uint8 skill2;
uint8 skill3;
uint8 skill4;
uint8 skill5;
}

event Dna1Updated(uint256 indexed _tokenId, DNA1 _dna);
event Dna2Updated(uint256 indexed _tokenId, DNA2 _dna);

mapping(uint256 => DNA1) public dna1;
mapping(uint256 => DNA2) public dna2;

string private __baseURI;
string private __contractURI;

constructor(address _fatherReceiver, string memory _initBaseURI, string memory _initContractURI) ERC721TradableMixin("Winzeland: Winzer", "Winzer") {
__baseURI = _initBaseURI;
__contractURI = _initContractURI;
// minting "AllFather" as first winzer with all zero traits.
DNA1 memory _dna1;
DNA2 memory _dna2;
_mint(_fatherReceiver, 0);
_setDna1(0, _dna1);
_setExtraDna(0, _dna2);
}

function mint(address player, DNA1 memory _dna1, DNA2 memory _dna2)
public onlyRole(MINTER_ROLE)
returns (uint256)
{
uint256 newItemId = totalSupply();
_mint(player, newItemId);

_setDna1(newItemId, _dna1);
_setExtraDna(newItemId, _dna2);

return newItemId;
}

function _setDna1(uint256 _tokenId, DNA1 memory _dna) internal {
dna1[_tokenId] = _dna;
emit Dna1Updated(_tokenId, _dna);
}

function _setExtraDna(uint256 _tokenId, DNA2 memory _dna) internal {
dna2[_tokenId] = _dna;
emit Dna2Updated(_tokenId, _dna);
}

function _baseURI() internal view override returns (string memory) {
return __baseURI;
}

function setBaseUri(string memory uri) public onlyRole(DEFAULT_ADMIN_ROLE) {
__baseURI = uri;
}

function contractURI() public view returns (string memory) {
return __contractURI;
}

function setContractURI(string memory uri) public onlyRole(DEFAULT_ADMIN_ROLE) {
__contractURI = uri;
}
}
68 changes: 68 additions & 0 deletions contracts/nfts/extras/ERC721Tradable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";
import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";

/**
* @title ERC721TradableMixin
* ERC721TradableMixin - ERC721 contract that whitelists a trading address
*/
abstract contract ERC721TradableMixin is ERC721Enumerable, AccessControlEnumerable, ContextMixin {
address public proxyRegistryAddress;

event ProxyRegistryAddressChanged(address indexed _newAddress);

constructor(
string memory _name,
string memory _symbol
) ERC721(_name, _symbol) {
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
}

/**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings.
*/
function isApprovedForAll(address _owner, address _operator)
override
public
view
returns (bool)
{
// Whitelist OpenSea proxy contract for easy trading.
TradableProxyRegistry proxyRegistry = TradableProxyRegistry(proxyRegistryAddress);
if (proxyRegistry.whitelistedOperators(_operator)) {
return true;
}

return super.isApprovedForAll(_owner, _operator);
}

function setProxyRegistryAddress(address _proxyRegistryAddress) public onlyRole(DEFAULT_ADMIN_ROLE) {
proxyRegistryAddress = _proxyRegistryAddress;
emit ProxyRegistryAddressChanged(_proxyRegistryAddress);
}

function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Enumerable, AccessControlEnumerable) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId
|| interfaceId == type(IAccessControlEnumerable).interfaceId
|| super.supportsInterface(interfaceId);
}

function owner() public view returns (address) {
return getRoleMember(DEFAULT_ADMIN_ROLE, 0);
}

function _msgSender()
internal
override
view
returns (address sender)
{
return msgSender();
}
}
2 changes: 1 addition & 1 deletion contracts/provisional/WinzerMarketingAirdrop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract WinzerMarketingAirdrop is Ownable {
_dna.eyes = 9;
_dna.eyebrows = 8;
_dna.nose = 2;
_dna.scars = 0;
// _dna.scars = 0;

WinzerERC721.DNA2 memory _extraDna;
_extraDna.makeup = 4;
Expand Down
8 changes: 4 additions & 4 deletions contracts/resources/ResourcesERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ contract ResourcesERC1155 is ERC1155TradableMixin {
int8 value4;
uint8 attr5;
int8 value5;
uint8 attr6;
int8 value6;
// uint8 attr6;
// int8 value6;
}

event MetadataUpdated(uint256 indexed _id, Metadata _metadata);
Expand Down Expand Up @@ -94,7 +94,7 @@ contract ResourcesERC1155 is ERC1155TradableMixin {
return __contractURI;
}

function setContractURI(string memory uri) public onlyRole(DEFAULT_ADMIN_ROLE) {
__contractURI = uri;
function setContractURI(string memory _uri) public onlyRole(DEFAULT_ADMIN_ROLE) {
__contractURI = _uri;
}
}
Loading