all files / contracts/ LandXNFT.sol

91.67% Statements 11/12
95% Branches 19/20
85.71% Functions 6/7
96.3% Lines 26/27
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103                                                                162× 162× 162× 162× 162×                               57× 56×       55× 54× 54× 54× 54× 54× 54× 54× 54× 54× 54×                                                      
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;
 
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "./interfaces/IKeyProtocolVariables.sol";
import "./interfaces/IxTokenRouter.sol";
 
contract LandXNFT is ERC1155, Ownable, AccessControl {
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
 
    IxTokenRouter public xTokenRouter;
    IKeyProtocolVariables public keyProtocolValues;
 
    // other parameters
    string private _baseTokenURI =
        "http://dev-landx-nfts.s3-website-us-east-1.amazonaws.com/j/";
 
    mapping(uint256 => uint256) public landArea; // total area in square-meters
    mapping(uint256 => uint256) public tillableArea; // tillable area in square-meters
    mapping(uint256 => uint256) public cropShare; //crop share
    mapping(uint256 => string) public crop; // ["SOY", "RICE" ....]
    mapping(uint256 => address) public validator; // validator or landowner
    mapping(uint256 => uint256) public validatorFee;
    mapping(uint256 => bytes32) public lienAgreementHash; //sha256 hash of lien documents
    mapping(uint256 => address) public initialOwner;
    mapping(uint256 => string) public metadataUri;
 
    constructor(address _xTokenRouter, address _keyProtocolValues, string memory _uri)
        ERC1155(_baseTokenURI)
    {
        xTokenRouter = IxTokenRouter(_xTokenRouter);
        keyProtocolValues = IKeyProtocolVariables(_keyProtocolValues);
        _baseTokenURI = _uri;
        _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _grantRole(MINTER_ROLE, msg.sender);
    }
 
    /**@dev sets the token details. price is in *wei* */
    function setDetailsAndMint(
        uint256 _index,
        uint256 _landArea,
        uint256 _tillableArea,
        uint256 _cropShare,
        address _validator,
        uint256 _validatorFee,
        bytes32 _lienAgreementHash,
        string memory _crop,
        address _to,
        string memory _uri
    ) public EonlyRole(MINTER_ROLE) {
        require(initialOwner[_index] == address(0), "tokenID already minted");
        require(
            xTokenRouter.getXToken(_crop) != address(0),
            "xToken is not defined"
        );
        require(_validatorFee <= keyProtocolValues.maxValidatorFee(),"validator's fee to high");
        landArea[_index] = _landArea;
        tillableArea[_index] = _tillableArea;
        cropShare[_index] = _cropShare;
        crop[_index] = _crop;
        validator[_index] = _validator;
        lienAgreementHash[_index] = _lienAgreementHash;
        initialOwner[_index] = _to;
        validatorFee[_index] = _validatorFee;
        metadataUri[_index] = _uri;
        _mint(_to, _index, 1, "");
    }
 
    //burns one token
    function burn(
        address account,
        uint256 id,
        uint256 value
    ) public virtual {
        require(
            account == _msgSender() || isApprovedForAll(account, _msgSender()),
            "ERC1155: caller is not owner nor approved"
        );
        _burn(account, id, value);
        initialOwner[id] = address(0);
    }
 
    function setBaseURI(string memory newuri) public onlyOwner {
        require(bytes(newuri).length > 0, "empty string");
        _baseTokenURI = newuri;
    }
 
    function uri(uint256 tokenId) public view override returns (string memory) {
        return string(abi.encodePacked(_baseTokenURI, metadataUri[tokenId]));
    }
 
    function setXTokenRouter(address _router) public onlyOwner {
        require(_router != address(0), "zero address is not allowed");
        xTokenRouter = IxTokenRouter(_router);
    }
 
    function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155, AccessControl) returns (bool) {
        return super.supportsInterface(interfaceId);
    }
}