NEP-10: Invoice Token Standard (NRC-10)

NEP10
TitleInvoice Token Standard (NRC-10)
Author(s)Yong Liu, Evan Liu
Discussions Tohttps://github.com/newtonproject/NEPs/issues/10
CategoryTechnical
TypeNRC
StatusDraft
Created2020-04-29

Simple Summary #

A standard interface for invoice token.

Abstract #

The following standard allows for the implementation of a standard API for invoice token within smart contracts. This standard provides basic functionality to issue、reimburse and invalidate invoice token.

Motivation #

A standard interface allows tax/invoice/financial applications to work with invoice token on NewChain. We provide for simple invoiceToken smart contracts as well as contracts that track an arbitrarily large number of invoice tokens.
The invoice token will curb malpractice and document forgery in taxation and simplify procedures.

Specification #

Meta Data #

ItemDescriptionBehaviors/Properties
Ownercan take full control of contractdeploy contract, add/remove addmin, set fee
Adminmanage enterpriseauthorize/revoke enterprise
Enterprisemanage token(Invoice)issue/reimburse/invalidate token
Feeissue token(invoice) feeuint ISSAC
FeeAddressfee withdrawal to this address
Invoicecontains operatorAddress, sellerTaxNumber, buyerTaxNumber, operatorName, invoiceInfo, status, financialstatus: positive、negative(reversal)、blank cancellation、cancellation, financial: received、recorded

Interaction / Functions #

FunctionDescriptionBehaviors/Properties
owner
addAdminadd admin to this contractpermission: owner
removeAdminremove admin from this contractpermission: owner
setFeeset issue fee,uint ISSACpermission: owner
setFeeAddressset issue fee withdrawal addresspermission: owner
withdrawwithdrawal to feeAddresspermission: owner
admin
authorizeauthorized _enterpriseAddress to join contractpermission: admin
revokerevoke _enterpriseAddress from this contractpermission: admin
enterprise
issueissue new token(Invoice) by msg.senderpermission: enterprise
issueFromissue new token(Invoice) by the approved address of the sellerpermission: enterprise
reimbursechange Invoice financial status from received to recordedpermission: enterprise
invalidatechange Invoice status from positive to _newStatuspermission: enterprise
setApprovalForAllenable or disable approval for a third party (“operator”) to manage all of msg.sender’s invoice tokenpermission: enterprise
Query
totalSupplyreturn issue invoices fee total
balanceOfSellerreturn sell invoices count
balanceOfBuyerreturn buy invoices count
tokenByIdreturn Invoice info
getFeereturn issue invoice fee
getFeeSumreturn contract revenue
getFeeBalancereturn contract balance
isApprovedForAllcheck is authorizationed
isExistcheck token is existed

Test Cases #

The reference implementation contains all the tests.

Implementation #

pragma solidity ^0.5.0;

interface INRC10{
    ///////////////////////////////////////////////////
    //       function for owner                      //
    ///////////////////////////////////////////////////

    event AdminAdded(address _admin);
    function addAdmin (address _admin) external public onlyOwner;

    event AdminRemoved(address _admin);
    function removeAdmin (address _admin) external public onlyOwner;

    event SetFeeSeted(uint _fee);
    //set issue fee,uint ISSAC
    function setFee(uint _fee) external public onlyOwner;

    event FeeAddressSeted(address _feeAddress);
    //set issue fee withdrawal address
    function setFeeAddress(address payable _feeAddress) external public onlyOwner;

    event FeeAndFeeAddressSeted(uint _fee, address _feeAddress);
    function setFeeAndFeeAddress(uint _fee, address payable _feeAddress) external public onlyOwner;

    event WithdrawalSuccess(address indexed _to, uint _amount);
    //uint ISSAC
    function withdraw(uint _withraw_amount) external public onlyOwner;

    ///////////////////////////////////////////////////
    //       function for admin                      //
    ///////////////////////////////////////////////////

    event AuthorizeSuccess(address _admin, address _enterpriseAddress, string _taxNumber);
    //authorized enterprise to join contract
    function authorize (address _enterpriseAddress, string memory _taxNumber) external public;

    event RevokeSuccess(address _admin, address _enterpriseAddress);
    //revoke enterprise
    function revoke (address _enterpriseAddress) external public;

    ///////////////////////////////////////////////////
    //       function for enterprise                 //
    ///////////////////////////////////////////////////

    event Issued(address _send, string _from, string _to, bytes32 _tokenId);
    //issue Invoice
    function issue(string memory _to, bytes32 _tokenId, string memory _operatorName, string memory _invoiceInfo) external payable public;

    function issueFrom(string memory _from, string memory _to, bytes32 _tokenId, string memory _operatorName, string memory _invoiceInfo) external payable public;

    event ReimburseSuccess(address _enterprise, bytes32 _tokenId);
    function reimburse(bytes32 _tokenId) external public;

    event InvalidateSuccess(address _enterprise, bytes32 _tokenId, uint8 _newStatus);
    function invalidate(bytes32 _tokenId, uint8 _newStatus) external public;

    event ApprovalForAllSeted(address _from, address _operator, bool _approved);

    function setApprovalForAll(address _operator, bool _approved) external public;

    ///////////////////////////////////////////////////
    //       function for all                        //
    ///////////////////////////////////////////////////
    //return issue invoices total
    function totalSupply() external public view returns (uint);

    //return sell invoices count
    function balanceOfSeller(string memory _taxNumber) external public view returns (uint);

    // return buy invoices count
    function balanceOfBuyer(string memory _taxNumber) external public view returns (uint);

    //return issue invoice fee, uint ISSAC
    function getFee()  external public view returns (uint);

    //return contract revenue,uint ISSAC
    function getFeeSum()  external public view returns (uint);

    //return contract balance,uint ISSAC
    function getFeeBalance()  external public view returns (uint);

    //return is authorizationed
    function isApprovedForAll(address _owner, address _operator)  external public view returns (bool);

    //return invoce info
    function tokenById(bytes32 _tokenId) external public view returns;

    function isExist(bytes32 _tokenId)  external public view returns (bool);
}

The reference implementation

References #

  1. ERC-721 Token Standard. https://eips.ethereum.org/EIPS/eip-721

Copyright and related rights waived via CC0.