Skip to content
Open
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
128 changes: 128 additions & 0 deletions Chinese Simplified/ERC875Auction.sol
Original file line number Diff line number Diff line change
@@ -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 <minimumBidIncrement> 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;
}
}
219 changes: 219 additions & 0 deletions Chinese Simplified/ERCTokenImplementation.sol
Original file line number Diff line number Diff line change
@@ -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;
}
}

21 changes: 21 additions & 0 deletions Chinese Simplified/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
Loading