From 395af54cd9e214e504d6171e1dd273ed7b429939 Mon Sep 17 00:00:00 2001 From: Jason-Wanxt <61458343+Jason-Wanxt@users.noreply.github.com> Date: Thu, 10 Mar 2022 14:10:28 +0800 Subject: [PATCH 1/5] New translations ERC875Auction.sol (Chinese Simplified) --- Chinese Simplified/ERC875Auction.sol | 128 +++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 Chinese Simplified/ERC875Auction.sol diff --git a/Chinese Simplified/ERC875Auction.sol b/Chinese Simplified/ERC875Auction.sol new file mode 100644 index 0000000..3e272b4 --- /dev/null +++ b/Chinese Simplified/ERC875Auction.sol @@ -0,0 +1,128 @@ +pragma solidity ^0.4.21; + +contract ERC875Interface { + function trade(uint256 expiry, uint256[] tokenIndices, uint8 v, bytes32 r, bytes32 s) public payable; + function passTo(uint256 expiry, uint256[] tokenIndices, uint8 v, bytes32 r, bytes32 s, address recipient) public; + function name() public view returns(string); + function symbol() public view returns(string); + function getAmountTransferred() public view returns (uint); + function balanceOf(address _owner) public view returns (uint256[]); + function myBalance() public view returns(uint256[]); + function transfer(address _to, uint256[] tokenIndices) public; + function transferFrom(address _from, address _to, uint256[] tokenIndices) public; + function approve(address _approved, uint256[] tokenIndices) public; + function endContract() public; + function contractType() public pure returns (string); + function getContractAddress() public view returns(address); + } + +contract ERC875Auction +{ + address public beneficiary; + uint public biddingEnd; + bool public ended; + uint public minimumBidIncrement; + address public holdingContract; + uint256[] public contractIndices; + + mapping(address => uint) public bids; + + // Events that will be fired on changes. + event HighestBidIncreased(address bidder, uint amount); + event AuctionEnded(address winner, uint highestBid); + + address public highestBidder; + uint public highestBid; + + modifier onlyBefore(uint _time) {require(now < _time); _;} + modifier onlyAfter(uint _time) {require(now > _time); _;} + modifier notBeneficiary(address addr) {require(addr != beneficiary); _;} + modifier bidIsSufficientlyHiger(uint value) {require(value > (highestBid + minimumBidIncrement)); _;} + modifier notAlreadyEnded() {require(ended == false); _;} + modifier addressHasSufficientBalance(address bidder, uint value) {require(bidder.balance >= value); _;} + modifier auctionHasEnded() {require(ended == true); _;} + modifier organiserOrBeneficiaryOnly() + { + if(!(msg.sender == beneficiary || msg.sender == holdingContract)) revert(); + else _; + } + + constructor( + uint _biddingTime, + address _beneficiary, + uint _minBidIncrement, + address _ERC875ContractAddr, + uint256[] _tokenIndices + ) public + { + beneficiary = _beneficiary; + biddingEnd = block.timestamp + _biddingTime; + minimumBidIncrement = _minBidIncrement; + ended = false; + holdingContract = _ERC875ContractAddr; + contractIndices = _tokenIndices; + } + + // Auction participant submits their bid. + // This only needs to be the value for this single use auction contract + function bid(uint value) + public + onlyBefore(biddingEnd) + notBeneficiary(msg.sender) // beneficiary can't participate in auction + bidIsSufficientlyHiger(value) // bid must be greater than the last one + addressHasSufficientBalance(msg.sender, value) // check that bidder has the required balance + { + bids[msg.sender] = value; + highestBid = value; + highestBidder = msg.sender; + emit HighestBidIncreased(highestBidder, highestBid); + } + + // Contract can be killed at any time - note that no assets are held by the contract + function endContract() public organiserOrBeneficiaryOnly + { + selfdestruct(beneficiary); + } + + /// End the auction - called by the winner, send eth to the beneficiatiary and send ERC875 tokens to the highest bidder + /// Can only be called by the winner, who must attach the ETH amount to the transaction + function auctionEnd() + public + onlyAfter(biddingEnd) + notAlreadyEnded() payable + { + require(!ended); + require(msg.value >= highestBid); + require(msg.sender == highestBidder); + + ERC875Interface tokenContract = ERC875Interface(holdingContract); + + //Atomic swap the ERC875 token(s) and the highestBidder's ETH + bool completed = tokenContract.transferFrom(beneficiary, highestBidder, contractIndices); + //only have two outcomes from transferFromContract() - all tokenss are transferred or none (uses revert) + if (completed) beneficiary.transfer(msg.value); + + ended = true; + emit AuctionEnded(highestBidder, highestBid); + } + + // Start new auction + function startNewAuction( + uint _biddingTime, + address _beneficiary, + uint _minBidIncrement, + address _ERC875ContractAddr, + uint256[] _tokenIndices) public + auctionHasEnded() + { + beneficiary = _beneficiary; + biddingEnd = block.timestamp + _biddingTime; + minimumBidIncrement = _minBidIncrement; + ended = false; + holdingContract = _ERC875ContractAddr; + contractIndices = _tokenIndices; + bids.delete(); + highestBid = 0; + highestBidder = 0; + } +} From b5d801269828f4435d6d0e22919e26e6e8a36709 Mon Sep 17 00:00:00 2001 From: Jason-Wanxt <61458343+Jason-Wanxt@users.noreply.github.com> Date: Thu, 10 Mar 2022 14:10:29 +0800 Subject: [PATCH 2/5] New translations ERCTokenImplementation.sol (Chinese Simplified) --- Chinese Simplified/ERCTokenImplementation.sol | 219 ++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 Chinese Simplified/ERCTokenImplementation.sol diff --git a/Chinese Simplified/ERCTokenImplementation.sol b/Chinese Simplified/ERCTokenImplementation.sol new file mode 100644 index 0000000..ddf3ecb --- /dev/null +++ b/Chinese Simplified/ERCTokenImplementation.sol @@ -0,0 +1,219 @@ +contract 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. + /// @return `true` if the contract implements `interfaceID` and + /// `interfaceID` is not 0xffffffff, `false` otherwise + function supportsInterface(bytes4 interfaceID) external view returns (bool); +} + +contract ERC875 /* is ERC165 */ +{ + event Transfer(address indexed _from, address indexed _to, uint256[] tokenIndices); + + function name() constant public returns (string name); + function symbol() constant public returns (string symbol); + function balanceOf(address _owner) public view returns (uint256[] _balances); + function transfer(address _to, uint256[] _tokens) public; + function transferFrom(address _from, address _to, uint256[] _tokens) public; + + //optional + //function totalSupply() public constant returns (uint256 totalSupply); + function trade(uint256 expiryTimeStamp, uint256[] tokenIndices, uint8 v, bytes32 r, bytes32 s) public payable; + //function ownerOf(uint256 _tokenId) public view returns (address _owner); +} + +pragma solidity ^0.4.17; +contract Token is ERC875 +{ + uint totalTickets; + mapping(address => uint256[]) inventory; + uint16 ticketIndex = 0; //to track mapping in tickets + uint expiryTimeStamp; + address owner; // the address that calls selfdestruct() and takes fees + address admin; + uint transferFee; + uint numOfTransfers = 0; + string public name; + string public symbol; + uint8 public constant decimals = 0; //no decimals as tickets cannot be split + + event Transfer(address indexed _from, address indexed _to, uint256[] tokenIndices); + event TransferFrom(address indexed _from, address indexed _to, uint _value); + + modifier adminOnly() + { + if(msg.sender != admin) revert(); + else _; + } + + function() public { revert(); } //should not send any ether directly + + // example: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], "MJ comeback", 1603152000, "MJC", "0x007bEe82BDd9e866b2bd114780a47f2261C684E3" + function Token( + uint256[] numberOfTokens, + string evName, + uint expiry, + string eventSymbol, + address adminAddr) public + { + totalTickets = numberOfTokens.length; + //assign some tickets to event admin + expiryTimeStamp = expiry; + owner = msg.sender; + admin = adminAddr; + inventory[admin] = numberOfTokens; + symbol = eventSymbol; + name = evName; + } + + function getDecimals() public pure returns(uint) + { + return decimals; + } + + // price is 1 in the example and the contract address is 0xfFAB5Ce7C012bc942F5CA0cd42c3C2e1AE5F0005 + // example: 0, [3, 4], 27, "0x2C011885E2D8FF02F813A4CB83EC51E1BFD5A7848B3B3400AE746FB08ADCFBFB", "0x21E80BAD65535DA1D692B4CEE3E740CD3282CCDC0174D4CF1E2F70483A6F4EB2" + // price is encoded in the server and the msg.value is added to the message digest, + // if the message digest is thus invalid then either the price or something else in the message is invalid + function trade(uint256 expiry, + uint256[] tokenIndices, + uint8 v, + bytes32 r, + bytes32 s) public payable + { + //checks expiry timestamp, + //if fake timestamp is added then message verification will fail + require(expiry > block.timestamp || expiry == 0); + //id 1 for mainnet + bytes12 prefix = "ERC800-CNID1"; + bytes32 message = encodeMessage(prefix, msg.value, expiry, tokenIndices); + address seller = ecrecover(message, v, r, s); + + for(uint i = 0; i < tokenIndices.length; i++) + { // transfer each individual tickets in the ask order + uint index = uint(tokenIndices[i]); + require((inventory[seller][index] > 0)); // 0 means ticket sold. + inventory[msg.sender].push(inventory[seller][index]); + inventory[seller][index] = 0; // 0 means ticket sold. + } + seller.transfer(msg.value); + } + + + //must also sign in the contractAddress + //prefix must contain ERC and chain id + function encodeMessage(bytes12 prefix, uint value, + uint expiry, uint256[] tokenIndices) + internal view returns (bytes32) + { + bytes memory message = new bytes(96 + tokenIndices.length * 2); + address contractAddress = getContractAddress(); + for (uint i = 0; i < 32; i++) + { // convert bytes32 to bytes[32] + // this adds the price to the message + message[i] = byte(bytes32(value << (8 * i))); + } + + for (i = 0; i < 32; i++) + { + message[i + 32] = byte(bytes32(expiry << (8 * i))); + } + + for(i = 0; i < 12; i++) + { + message[i + 64] = byte(prefix << (8 * i)); + } + + for(i = 0; i < 20; i++) + { + message[76 + i] = byte(bytes20(bytes20(contractAddress) << (8 * i))); + } + + for (i = 0; i < tokenIndices.length; i++) + { + // convert int[] to bytes + message[96 + i * 2 ] = byte(tokenIndices[i] >> 8); + message[96 + i * 2 + 1] = byte(tokenIndices[i]); + } + + return keccak256(message); + } + + function name() public view returns(string) + { + return name; + } + + function symbol() public view returns(string) + { + return symbol; + } + + function getAmountTransferred() public view returns (uint) + { + return numOfTransfers; + } + + function isContractExpired() public view returns (bool) + { + if(block.timestamp > expiryTimeStamp) + { + return true; + } + else return false; + } + + function balanceOf(address _owner) public view returns (uint256[]) + { + return inventory[_owner]; + } + + function myBalance() public view returns(uint256[]) + { + return inventory[msg.sender]; + } + + function transfer(address _to, uint256[] tokenIndices) public + { + for(uint i = 0; i < tokenIndices.length; i++) + { + require(inventory[msg.sender][i] != 0); + //pushes each element with ordering + uint index = uint(tokenIndices[i]); + inventory[_to].push(inventory[msg.sender][index]); + inventory[msg.sender][index] = 0; + } + } + + function transferFrom(address _from, address _to, uint256[] tokenIndices) + adminOnly public + { + bool isadmin = msg.sender == admin; + for(uint i = 0; i < tokenIndices.length; i++) + { + require(inventory[_from][i] != 0 || isadmin); + //pushes each element with ordering + uint index = uint(tokenIndices[i]); + inventory[_to].push(inventory[_from][index]); + inventory[_from][index] = 0; + } + } + + function endContract() public + { + if(msg.sender == owner) + { + selfdestruct(owner); + } + else revert(); + } + + function getContractAddress() public view returns(address) + { + return this; + } +} + From 0a366a8c6c8051958c41fdaf04f479f319bfffb8 Mon Sep 17 00:00:00 2001 From: Jason-Wanxt <61458343+Jason-Wanxt@users.noreply.github.com> Date: Thu, 10 Mar 2022 14:10:30 +0800 Subject: [PATCH 3/5] New translations LICENSE (Chinese Simplified) --- Chinese Simplified/LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Chinese Simplified/LICENSE diff --git a/Chinese Simplified/LICENSE b/Chinese Simplified/LICENSE new file mode 100644 index 0000000..be12444 --- /dev/null +++ b/Chinese Simplified/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 AlphaWallet + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 2a3ba8dd183d8d11b22bd8e2bbd00f53805dda77 Mon Sep 17 00:00:00 2001 From: Jason-Wanxt <61458343+Jason-Wanxt@users.noreply.github.com> Date: Thu, 10 Mar 2022 14:10:31 +0800 Subject: [PATCH 4/5] New translations README.md (Chinese Simplified) --- Chinese Simplified/README.md | 85 ++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Chinese Simplified/README.md diff --git a/Chinese Simplified/README.md b/Chinese Simplified/README.md new file mode 100644 index 0000000..dc9f91e --- /dev/null +++ b/Chinese Simplified/README.md @@ -0,0 +1,85 @@ +# ERC875-Example +An example implementation of our new ERC spec draft. + +Create your own here: https://alphawallet.github.io/ERC875-token-factory/index + +Test it out here: https://rinkeby.etherscan.io/address/0xffab5ce7c012bc942f5ca0cd42c3c2e1ae5f0005 + +Referenced here: https://github.com/ethereum/EIPs/issues/875 + + contract ERC + { + event Transfer(address indexed _from, address indexed _to, uint256 _tokenId); + event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId); + + function name() constant returns (string name); + function symbol() constant returns (string symbol); + function balanceOf(address _owner) public view returns (uint256[] _balances); + function transfer(address _to, uint256[] _tokens) public; + function transferFrom(address _from, address _to, uint256[] _tokens) public; + + //optional + function totalSupply() constant returns (uint256 totalSupply); + function trade(uint256 expiryTimeStamp, uint256[] tokenIndices, uint8 v, bytes32 r, bytes32 s) public payable + function ownerOf(uint256 _tokenId) public view returns (address _owner); + } + +## Summary +A simple non fungible token standard that allows batching tokens into lots and settling p2p atomic transfers in one transaction. + +## Purpose +While other standards allow the user to transfer a non-fungible token, they require one transaction per token, this is heavy on gas and partially responsible for clogging the ethereum network. There are also few definitions for how to do a simple atomic swap. + +## Rinkeby example +This standard has been implemented in an example contract on rinkeby: https://rinkeby.etherscan.io/address/0xffab5ce7c012bc942f5ca0cd42c3c2e1ae5f0005 + +## Specification + +### function name() constant returns (string name) + +returns the name of the contract e.g. CarLotContract + +### function symbol() constant returns (string symbol) + +Returns a short string of the symbol of the in-fungible token, this should be short and generic as each token is non-fungible. + +### function balanceOf(address _owner) public view returns (uint256[] balance) + +Returns an array of the users balance. + +### function transfer(address _to, uint256[] _tokens) public; + +Transfer your unique tokens to an address by adding an array of the token indices. This compares favourable to ERC721 as you can transfer a bulk of tokens in one go rather than one at a time. This has a big gas saving as well as being more convenient. + +### function transferFrom(address _from, address _to, uint256[] _tokens) public; + +Transfer a variable amount of tokens from one user to another. This can be done from an authorised party with a specified key e.g. contract owner. + +## Optional functions + +### function totalSupply() constant returns (uint256 totalSupply); + +Returns the total amount of tokens in the given contract, this should be optional as assets might be allocated and issued on the fly. This means that supply is not always fixed. + +### function ownerOf(uint256 _tokenId) public view returns (address _owner); + +Returns the owner of a particular token, I think this should be optional as not every token contract will need to track the owner of a unique token and it costs gas to loop and map the token id owners each time the balances change. + +### function trade(uint256 expiryTimeStamp, uint256[] tokenIndices, uint8 v, bytes32 r, bytes32 s) public payable + +A function which allows a user to sell a batch of non-fungible tokens without paying for the gas fee (only the buyer has to). This is achieved by signing an attestation containing the amount of tokens to sell, the contract address, an expiry timestamp, the price and a prefix containing the ERC spec name and chain id. A buyer can then pay for the deal in one transaction by attaching the appropriate ether to satisfy the deal. + +This design is also more efficient as it allows orders to be done offline until settlement as opposed to creating orders in a smart contract and updating them. The expiry timestamp protects the seller against people using old orders. + +This opens up the gates for a p2p atomic swap but should be optional to this standard as some may not have use for it. + +Some protections need to be added to the message such as encoding the chain id, contract address and the ERC spec name to prevent replays and spoofing people into signing message that allow a trade. + + + + +# Donations +If you support the cause, we could certainly use donations to help fund development: + +0xbc8dAfeacA658Ae0857C80D8Aa6dE4D487577c63 + From 405e65ca87eae44958e1a2c5e3fdb0a0f698bc04 Mon Sep 17 00:00:00 2001 From: Jason-Wanxt <61458343+Jason-Wanxt@users.noreply.github.com> Date: Thu, 10 Mar 2022 14:10:32 +0800 Subject: [PATCH 5/5] New translations TradeImplementationExample.java (Chinese Simplified) --- .../TradeImplementationExample.java | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 Chinese Simplified/TradeImplementationExample.java diff --git a/Chinese Simplified/TradeImplementationExample.java b/Chinese Simplified/TradeImplementationExample.java new file mode 100644 index 0000000..63f09eb --- /dev/null +++ b/Chinese Simplified/TradeImplementationExample.java @@ -0,0 +1,127 @@ +package tapi.utils; + +import org.web3j.crypto.ECKeyPair; +import org.web3j.crypto.Sign; +import java.math.BigInteger; +import java.nio.ByteBuffer; +import java.nio.ShortBuffer; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by sangalli on 12/2/18. + */ + +class TransactionDetails +{ + BigInteger value; + List ticketIndices; + Sign.SignatureData signatureData; +} + +public class TradeImplementationExample +{ + + private static final String contractAddress = "fFAB5Ce7C012bc942F5CA0cd42c3C2e1AE5F0005"; + + public static void main(String[] args) + { + short[] ticketPlaces = new short[]{3, 4}; + //zero timestamp means unlimited + byte[] msg = encodeMessageForTrade(BigInteger.ONE, BigInteger.ZERO, ticketPlaces); + List indices = new ArrayList<>(); + for(int i = 0; i < ticketPlaces.length; i++) + { + indices.add(BigInteger.valueOf(ticketPlaces[i])); + } + TransactionDetails td = createTrade(msg, indices, BigInteger.ONE); + + System.out.println("Price: 1 "); + System.out.println("expiry: 0 (does not expiry)"); + System.out.println("Signature v value: " + td.signatureData.getV()); + System.out.println("Signature r value: 0x" + bytesToHex(td.signatureData.getR())); + System.out.println("Signature s value: 0x" + bytesToHex(td.signatureData.getS())); + System.out.println("Ticket indices: 3, 4"); + } + + public static byte[] encodeMessageForTrade(BigInteger price, BigInteger expiryTimestamp, short[] tickets) + { + byte[] priceInWei = price.toByteArray(); + byte[] expiry = expiryTimestamp.toByteArray(); + ByteBuffer message = ByteBuffer.allocate(96 + tickets.length * 2); + byte[] leadingZeros = new byte[32 - priceInWei.length]; + message.put(leadingZeros); + message.put(priceInWei); + byte[] leadingZerosExpiry = new byte[32 - expiry.length]; + message.put(leadingZerosExpiry); + message.put(expiry); + byte[] prefix = "ERC800-CNID1".getBytes(); + byte[] contract = hexStringToBytes(contractAddress); + message.put(prefix); + message.put(contract); + ShortBuffer shortBuffer = message.slice().asShortBuffer(); + shortBuffer.put(tickets); + + return message.array(); + } + + private static String bytesToHex(byte[] bytes) + { + final char[] hexArray = "0123456789ABCDEF".toCharArray(); + char[] hexChars = new char[bytes.length * 2]; + for ( int j = 0; j < bytes.length; j++ ) + { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + String finalHex = new String(hexChars); + return finalHex; + } + + private static byte[] hexStringToBytes(String s) + { + int len = s.length(); + byte[] data = new byte[len / 2]; + for (int i = 0; i < len; i += 2) + { + data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + + Character.digit(s.charAt(i + 1), 16)); + } + return data; + } + + public static TransactionDetails createTrade(byte[] message, List indices, BigInteger price) + { + try + { + //Note: you can replace with your own key instead of using same key generated from BigInteger.ONE + Sign.SignatureData sigData = Sign.signMessage(message, + ECKeyPair.create(BigInteger.ONE)); + TransactionDetails TransactionDetails = new TransactionDetails(); + TransactionDetails.ticketIndices = indices; + TransactionDetails.value = price; + + byte v = sigData.getV(); + + String hexR = bytesToHex(sigData.getR()); + String hexS = bytesToHex(sigData.getS()); + + byte[] rBytes = hexStringToBytes(hexR); + byte[] sBytes = hexStringToBytes(hexS); + + BigInteger r = new BigInteger(rBytes); + BigInteger s = new BigInteger(sBytes); + + TransactionDetails.signatureData = new Sign.SignatureData(v, r.toByteArray(), s.toByteArray()); + + return TransactionDetails; + } + catch(Exception e) + { + e.printStackTrace(); + return null; + } + } + +}