Branch: master
Find file Copy path
f0efb23 Sep 27, 2018
1 contributor

Users who have contributed to this file

47 lines (39 sloc) 1.33 KB
contract Exchange():
def setup(token_addr: address): modifying
NewExchange: event({token: indexed(address), exchange: indexed(address)})
exchangeTemplate: public(address)
tokenCount: public(uint256)
token_to_exchange: address[address]
exchange_to_token: address[address]
id_to_token: address[uint256]
def initializeFactory(template: address):
assert self.exchangeTemplate == ZERO_ADDRESS
assert template != ZERO_ADDRESS
self.exchangeTemplate = template
def createExchange(token: address) -> address:
assert token != ZERO_ADDRESS
assert self.exchangeTemplate != ZERO_ADDRESS
assert self.token_to_exchange[token] == ZERO_ADDRESS
exchange: address = create_with_code_of(self.exchangeTemplate)
self.token_to_exchange[token] = exchange
self.exchange_to_token[exchange] = token
token_id: uint256 = self.tokenCount + 1
self.tokenCount = token_id
self.id_to_token[token_id] = token
log.NewExchange(token, exchange)
return exchange
def getExchange(token: address) -> address:
return self.token_to_exchange[token]
def getToken(exchange: address) -> address:
return self.exchange_to_token[exchange]
def getTokenWithId(token_id: uint256) -> address:
return self.id_to_token[token_id]