Skip to content

Commit

Permalink
Merge branch 'master' into etx
Browse files Browse the repository at this point in the history
  • Loading branch information
caktux committed Jan 6, 2016
2 parents 4199ff8 + 6e14058 commit 8857dce
Show file tree
Hide file tree
Showing 9 changed files with 365 additions and 108 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Methods (with serpent type definitions):
withdraw:[int256,int256]:int256,
add_market:[int256,int256,int256,int256,int256,int256]:int256,
get_market_id:[int256]:int256,
get_market_id_by_name:[int256]:int256,
get_last_market_id:[]:int256,
get_market:[int256]:int256[],
get_trade:[int256]:int256[],
Expand Down Expand Up @@ -151,11 +152,16 @@ cancel(trade_id)
add_market(currency_name, contract_address, decimal_precision, price_denominator, minimum_total, category)
```

### Getting a market's ID
### Getting a market's ID by contract address
```
get_market_id(contract_address)
```

### Getting a market's ID by name
```
get_market_id_by_name(name)
```

#### Market names

Market names follow the "<currency name>/ETH" convention. When registering a new market, submit the currency name as a three or four letter uppercase identifier, ex.: "BOB" for BobCoin.
Expand Down
80 changes: 63 additions & 17 deletions contracts/etherex.se
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
# EtherEx
#

data last_market

data markets[2^160](id, name, contract, decimals, precision, minimum, category, last_price, owner, block, total_trades, last_trade, trade_ids[](id, next_id, prev_id))
data markets_id[2^160](id) # Reverse Market ID lookup
data markets_id[2^160](id) # Reverse Market ID lookup by contract address
data markets_name[2^160](id) # Reverse Market ID lookup by name
data trades[2^160](id, type, market, amount, price, owner, block, refhash)
data balances[][](available, trading)
data last_market

event log_price(market:indexed, type, price, amount, timestamp)
event log_add_tx(market:indexed, sender, type, price, amount, tradeid)
Expand All @@ -24,7 +24,8 @@ event log_withdraw(market:indexed, sender:indexed, amount)
event log_cancel(market:indexed, sender, price, amount, tradeid)
event log_market(id)

extern subcurrency: [transfer:[int256,int256]:int256, transferFrom:[int256,int256,int256]:int256, issue:[int256,int256]:int256]
extern subcurrency: [allowance:[int256,int256]:int256, approve:[int256,int256]:int256, balance:[]:int256, balanceOf:[int256]:int256, transfer:[int256,int256]:int256, transferFrom:[int256,int256,int256]:int256, issue:[int256,int256]:int256]


# Trade types
macro BID: 1
Expand All @@ -42,6 +43,7 @@ macro ETX: 100000
macro SUCCESS: 1
macro FAILURE: 0


#
# Error codes
#
Expand All @@ -51,28 +53,41 @@ macro MISSING_AMOUNT: 2
macro MISSING_PRICE: 3
macro MISSING_MARKET_ID: 4

macro INSUFFICIENT_BALANCE: 11
macro INSUFFICIENT_TRADE_AMOUNT: 12
macro INSUFFICIENT_VALUE: 13
macro INSUFFICIENT_BALANCE: 10
macro INSUFFICIENT_TRADE_AMOUNT: 11
macro INSUFFICIENT_VALUE: 12

macro TRADE_AMOUNT_MISMATCH: 14
macro TRADE_ALREADY_EXISTS: 15
macro TRADE_AMOUNT_MISMATCH: 20
macro TRADE_ALREADY_EXISTS: 21
macro TRADE_SAME_BLOCK_PROHIBITED: 22

macro SAME_BLOCK_TRADE_PROHIBITED: 16
macro MARKET_NAME_INVALID: 30
macro MARKET_NAME_ALREADY_EXISTS: 31
macro MARKET_CONTRACT_INVALID: 32
macro MARKET_CATEGORY_INVALID: 33
macro MARKET_DECIMALS_INVALID: 34
macro MARKET_PRECISION_INVALID: 35
macro MARKET_MINIMUM_INVALID: 36

# TODO - Markets error codes
macro MARKET_NONSTANDARD_ALLOWANCE: 40
macro MARKET_NONSTANDARD_APPROVE: 41
macro MARKET_NONSTANDARD_BALANCEOF: 42
macro MARKET_NONSTANDARD_TRANSFER: 43
macro MARKET_NONSTANDARD_TRANSFERFROM: 44

#
# Function macros
#
macro refund():
if msg.value > 0:
send(msg.sender, msg.value)

macro check_trade($amount, $price, $market_id):
if not $amount:
if amount <= 0:
return(MISSING_AMOUNT)
if not $price:
if price <= 0:
return(MISSING_PRICE)
if not $market_id:
if market_id <= 0:
return(MISSING_MARKET_ID)

macro save_trade($type, $amount, $price, $market_id):
Expand Down Expand Up @@ -214,7 +229,7 @@ def trade(max_amount, trade_ids:arr):

# Make sure the trade has been mined, obvious HFT prevention
if block.number <= self.trades[trade_id].block:
return(SAME_BLOCK_TRADE_PROHIBITED)
return(TRADE_SAME_BLOCK_PROHIBITED)

# Get market
market_id = self.trades[trade_id].market
Expand Down Expand Up @@ -243,7 +258,8 @@ def trade(max_amount, trade_ids:arr):

# Check buy value
if value < minimum:
refund()
if max_value > 0:
send(msg.sender, max_value)
return(INSUFFICIENT_VALUE)

# Send ETH fee to ETX contract
Expand Down Expand Up @@ -401,7 +417,33 @@ def add_market(name, contract, decimals, precision, minimum, category):
# Get the next market ID
id = self.last_market + 1

# TODO - Check data...
if name <= 0:
return MARKET_NAME_INVALID
if self.markets_name[name].id:
return MARKET_NAME_ALREADY_EXISTS
if contract <= 0:
return MARKET_CONTRACT_INVALID
if category < 0:
return MARKET_CATEGORY_INVALID
if decimals < 0:
return MARKET_DECIMALS_INVALID
if precision < 0:
return MARKET_PRECISION_INVALID
if minimum < 0:
return MARKET_MINIMUM_INVALID

# Check Standard Token support
if contract.allowance(msg.sender, self) != 0:
return MARKET_NONSTANDARD_ALLOWANCE
if contract.approve(self, 0) != 1:
return MARKET_NONSTANDARD_APPROVE
if contract.balanceOf(self) != 0:
return MARKET_NONSTANDARD_BALANCEOF
if contract.transfer(msg.sender, 0) != 0:
return MARKET_NONSTANDARD_TRANSFER
if contract.transferFrom(self, msg.sender, 0) != 0:
return MARKET_NONSTANDARD_TRANSFERFROM

self.markets[id].id = id
self.markets[id].name = name
self.markets[id].contract = contract
Expand All @@ -415,6 +457,7 @@ def add_market(name, contract, decimals, precision, minimum, category):

# Set reverse lookup ID
self.markets_id[contract].id = id
self.markets_name[name].id = id

# Set last market ID
self.last_market = id
Expand All @@ -430,6 +473,9 @@ def add_market(name, contract, decimals, precision, minimum, category):
def get_market_id(address):
return(self.markets_id[address].id)

def get_market_id_by_name(name):
return(self.markets_name[name].id)

def get_last_market_id():
return(self.last_market)

Expand Down
19 changes: 5 additions & 14 deletions contracts/etx.se
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ data total
data accounts[2^160](balance, custodians[2^160](maxValue))

event Transfer(_from:indexed, _to:indexed, _value)
event Approved(_owner:indexed, _spender:indexed, _value)
event Unapproved(_owner:indexed, _spender:indexed)
event Approval(_owner:indexed, _spender:indexed, _value)

# Boolean success/failure
macro SUCCESS: 1
Expand All @@ -26,7 +25,6 @@ macro MINIMUM_VALUE_NOT_MET: 2

def init():
self.creator = msg.sender
self.accounts[msg.sender].balance = 100000000000

# Set exchange contract address for ETX issuance
def setExchange(_address):
Expand Down Expand Up @@ -116,19 +114,12 @@ def totalSupply():
return(self.total)

def approve(_spender, _value):
if _spender <= 0 or _value <= 0:
if _spender <= 0 or _value < 0:
return(FAILURE)
approvedValue = self.accounts[msg.sender].custodians[_spender].maxValue + _value
self.accounts[msg.sender].custodians[_spender].maxValue = approvedValue
log(type=Approved, msg.sender, _spender, approvedValue)
self.accounts[msg.sender].custodians[_spender].maxValue = _value
log(type=Approval, msg.sender, _spender, _value)
return(SUCCESS)

# Returns the amount which _spender is still allowed to direct debit from _address
# Returns the amount which _spender is still allowed to transfer from _address
def allowance(_address, _spender):
return(self.accounts[_address].custodians[_spender].maxValue)

# Unapprove _spender to withdraw from your account
def unapprove(_spender):
self.accounts[msg.sender].custodians[_spender].maxValue = 0
log(type=Unapproved, msg.sender, _spender)
return(SUCCESS)
2 changes: 1 addition & 1 deletion frontend/app/clients/EthereumClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ var EthereumClient = function(params) {
return;
}

// TODO watch for Approved when event is formalized as a standard
// TODO watch for Approval event when formalized as a standard
// Poll allowance meanwhile
var pollAllowance = function() {
subcontract.allowance.call(user.id, self.address, function(err, res) {
Expand Down
17 changes: 17 additions & 0 deletions frontend/app/js/abi/etherex.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,23 @@ module.exports = [
}
]
},
{
"constant": false,
"type": "function",
"name": "get_market_id_by_name(int256)",
"outputs": [
{
"type": "int256",
"name": "out"
}
],
"inputs": [
{
"type": "int256",
"name": "name"
}
]
},
{
"constant": false,
"type": "function",
Expand Down
35 changes: 1 addition & 34 deletions frontend/app/js/abi/sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,6 @@ module.exports = [
}
]
},
{
"constant": false,
"type": "function",
"name": "unapprove(int256)",
"outputs": [
{
"type": "int256",
"name": "out"
}
],
"inputs": [
{
"type": "int256",
"name": "_spender"
}
]
},
{
"inputs": [
{
Expand All @@ -152,7 +135,7 @@ module.exports = [
}
],
"type": "event",
"name": "Approved(int256,int256,int256)"
"name": "Approval(int256,int256,int256)"
},
{
"inputs": [
Expand All @@ -174,21 +157,5 @@ module.exports = [
],
"type": "event",
"name": "Transfer(int256,int256,int256)"
},
{
"inputs": [
{
"indexed": true,
"type": "int256",
"name": "_owner"
},
{
"indexed": true,
"type": "int256",
"name": "_spender"
}
],
"type": "event",
"name": "Unapproved(int256,int256)"
}
];
22 changes: 11 additions & 11 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "EtherEx",
"version": "0.9.10",
"version": "0.9.11",
"description": "EtherEx frontend",
"main": "app/app.jsx",
"scripts": {
Expand Down Expand Up @@ -28,11 +28,11 @@
},
"homepage": "https://github.com/etherex/etherex",
"devDependencies": {
"babel-core": "^6.3.17",
"babel-loader": "^6.2.0",
"babel-core": "^6.3.26",
"babel-loader": "^6.2.1",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"css-loader": "^0.23.0",
"css-loader": "^0.23.1",
"eslint": "^1.10.3",
"expect": "^1.13.4",
"file-loader": "^0.8.5",
Expand All @@ -46,7 +46,7 @@
"grunt-karma": "^0.12.1",
"grunt-webpack": "^1.0.11",
"json-loader": "^0.5.4",
"karma": "^0.13.15",
"karma": "^0.13.19",
"karma-chrome-launcher": "^0.2.2",
"karma-cli": "^0.1.1",
"karma-mocha": "^0.2.1",
Expand All @@ -70,20 +70,20 @@
"d3": "^3.5.12",
"flat": "^1.6.0",
"fluxxor": "^1.7.3",
"history": "=1.13.1",
"history": "^1.17.0",
"intl": "^1.0.1",
"intl-locales-supported": "^1.0.0",
"keymirror": "^0.1.1",
"lodash": "^3.10.1",
"numeral": "^1.5.3",
"react": "^0.14.3",
"react-addons-perf": "^0.14.3",
"react-addons-transition-group": "^0.14.3",
"react": "^0.14.5",
"react-addons-perf": "^0.14.5",
"react-addons-transition-group": "^0.14.5",
"react-bootstrap": "^0.28.1",
"react-dom": "^0.14.3",
"react-dom": "^0.14.5",
"react-intl": "^2.0.0-beta2",
"react-qr": "^0.0.2",
"react-router": "=1.0.2",
"react-router": "^1.0.3",
"si-prefix": "^0.1.0",
"techan": "caktux/techan.js",
"ua-parser-js": "^0.7.10",
Expand Down
Loading

0 comments on commit 8857dce

Please sign in to comment.