ERC-1175 ERC20 wallet and shop payment standard (Wallet & shop standard for all tokens (erc20))
Stagnant · Accounts & wallets · created 2018-06-21
A wallet and shop contract created by WalletCenter that lets payments with an existing ERC20 token be made in a single call instead of two separate calls to approve and transferFrom.
Why it is needed
To buy a product with an ERC20 token, the buyer first had to call approve on the shop address to allow use of the token, and then the shop or an intermediary contract had to call transferFrom again to take the tokens. This required building a new custom payment contract for each token or shop, and created trust issues between two separate transactions and different contracts. ERC-1175 has WalletCenter create wallets and shops directly, so a wallet can immediately verify whether the shop it intends to pay is trustworthy (created by WalletCenter), and bundles approve and transferFrom into a single paySafe call. It also provides shops with standard interface functions for inventory, expiration, and reputation (voting), reducing the need to write new payment logic for each token.
What to implement
function createWallet() public returns (address _wallet): Creates a wallet contract and adds it to the list. Returns the new wallet address.function isWallet(address _wallet) public constant returns (bool): Checks whether a given address is a wallet created by createWallet.function createShop(address _erc20) public returns (address _shop): Creates a shop contract for the specified ERC20 token and adds it to the list.function isShop(address _shop) public constant returns (bool): Checks whether a given address is a shop created by createShop.event Wallet(address indexed _owner, address indexed _wallet): An event for finding my wallet, recording the creator and wallet address.event Shop(address indexed _owner, address indexed _shop, address indexed _erc20): An event for finding my shop, recording the creator, shop address, and token address.function balanceOf(address _erc20) public constant returns (uint256 balance): Returns the wallet's balance of a specific token (or ETH if the address is zero).function withdrawal(address _erc20, uint256 _value) onlyOwner public returns (bool success): The wallet owner withdraws _value of their held tokens to themselves.function paySafe(address _shop, uint256 _item) onlyOwner onlyShop(_shop) public payable returns (bool success): Pays for item _item in a single call at a shop created (and thus verified as safe) by WalletCenter.function payUnsafe(address _shop, uint256 _item) onlyOwner public payable returns (bool success): Pays for item _item at a shop not created by (and thus unverified by) WalletCenter.function payCancel(address _shop, uint256 _item) onlyOwner public returns (bool success): Cancels payment and receives a refund, limited to weekly-model products.function refund(uint256 _item, uint256 _value) public payable returns (bool success): Receives a refund for item _item from the shop.event Pay(address indexed _shop, uint256 indexed _item, uint256 indexed _value): Records the shop, item, and amount when a payment is made from a wallet.event Refund(address indexed _shop, uint256 indexed _item, uint256 indexed _value): Records the shop, item, and amount when a wallet receives a refund.function balanceOf(address _erc20) public constant returns (uint256 balance): Returns the shop's balance of a specific token (or ETH).function withdrawal(address _erc20, uint256 _value) onlyOwner public returns (bool success): The shop owner withdraws _value of their held tokens to themselves.function pay(uint256 _item) onlyWallet(msg.sender) public payable returns (bool success): Receives payment for item _item from a wallet.function refund(address _buyer, uint256 _item, uint256 _value) onlyWallet(_buyer) onlyOwner public payable returns (bool success): Refunds amount _value for item _item to buyer wallet _buyer.function resister(uint8 _category, uint256 _price, uint256 _stock) onlyOwner public returns (uint256 _itemId): Registers a product for sale with a specified category, price, and inventory.function update(uint256 _item, uint256 _price, uint256 _stock) onlyOwner public: Changes a product's price or adds to its _stock.function price(uint256 _item) public constant returns (address _erc20, uint256 _value): Looks up the payment token address and price for item _item.function canBuy(address _who, uint256 _item) public constant returns (bool _canBuy): Checks whether address _who can purchase item _item.function isBuyer(address _who, uint256 _item) public constant returns (bool _buyer): Checks whether address _who is a buyer of item _item.function info(bytes _msgPack): Sets the shop information as msgpack bytes.function upVote(): Casts an upvote on this shop.function dnVote(): Casts a downvote on this shop.function about() view returns (address _erc20, uint256 _up, uint256 _down): Looks up the shop's token address and upvote/downvote counts.function infoItem(uint256 _item, bytes _msgPack): Sets the item information as msgpack bytes.function upVoteItem(uint256 _item): Casts an upvote on item _item.function dnVoteItem(uint256 _item): Casts a downvote on item _item.function aboutItem(uint256 _item) view returns (uint256 _price, uint256 _up, uint256 _down): Looks up the price and upvote/downvote counts of item _item.event Pay(address indexed _buyer, uint256 indexed _item, uint256 indexed _value): Records the buyer, item, and amount when a payment occurs at the shop.event Refund(address indexed _to, uint256 indexed _item, uint256 indexed _value): Records the refund target, item, and amount when the shop issues a refund.event Item(uint256 indexed _item, uint256 _price): Records when an item is registered or its price changes.event Info(bytes _msgPack): Records when the shop information changes.event InfoItem(uint256 indexed _item, bytes _msgPack): Records when the item information changes.
In depth
The three-tier WalletCenter, Wallet, Shop structure
The standard is divided into three contracts: WalletCenter, Wallet, and Shop. WalletCenter deploys Wallet and Shop directly via createWallet/createShop, and lets anyone check whether an address was created by it via isWallet/isShop. Wallet acts as a per-user token holding account, and Shop is tied to a single ERC20 token address (_erc20) and sells items. A shop created by WalletCenter is classified as a safe shop.
Reducing payment to a single call
Under the existing ERC20 payment flow, the buyer first allows the shop to spend tokens via approve(_spender,_value), and then the shop or an intermediary calls transferFrom(_from,_to,_value) to take the tokens, requiring two calls. ERC-1175 adds paySafe(_shop,_item) and payUnsafe(_shop,_item) to the Wallet contract so that, with a single call from the owner, the wallet internally looks up the item price, transfers the tokens to the shop, and calls the shop's pay function.
Safe shops and unsafe shops
paySafe has an onlyShop(_shop) condition, so it can only pay shops created by WalletCenter, which are confirmed via WalletCenter.isShop. payUnsafe has no such condition, so it can also pay shop interfaces not created by WalletCenter, but this means there is no guarantee that the shop can be trusted.
Item categories, stock, and expiration
Items registered via Shop's resister(_category,_price,_stock) behave differently depending on the category value. In the Appendix implementation, category 1 can be purchased only once with no stock or expiration, category 2 is a weekly (expiring) model that can be purchased again only after one week has passed since the last purchase, and category 3 is an item whose stock is consumed and can be bought repeatedly in bulk. canBuy and isBuyer are used to look up purchasability and buyer status.
Refunds and payment cancellation
Shop.refund(_buyer,_item,_value) is a function that lets the shop owner return tokens to a buyer, and Wallet.refund is the counterpart function that receives that refund on the wallet side. Wallet.payCancel(_shop,_item) is a function that cancels a payment and receives a refund, available only for weekly-model items.
Shop and item information and reputation
Shop uses info(_msgPack) and infoItem(_item,_msgPack) to store additional shop and item information as msgpack-formatted bytes, announced via the Info/InfoItem events. upVote/dnVote and upVoteItem/dnVoteItem allow casting upvotes and downvotes on shops and items, and about()/aboutItem(_item) let you look up the accumulated upvote/downvote counts.
Proposal status
This proposal was written in June 2018 and is in Stagnant status, with no further discussion ongoing. Note that its content may have changed since or it may never be adopted.