Skip to content

Commit

Permalink
Add comments to on chain market maker
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidKnott committed Dec 21, 2017
1 parent 13e760e commit 1281fd2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/market_maker/on_chain_market_maker.v.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
total_eth_qty: public(wei_value)
total_token_qty: public(currency_value)
# Constant set in `initiate` that's used to calculate
# the amount of ether/tokens that are exchanged
invariant: public(num(wei * currency))
token_address: address(ERC20)
owner: public(address)

# Sets the on chain market maker with its owner, intial token quantity,
# and initial ether quantity
@public
@payable
def initiate(token_addr: address, token_quantity: currency_value):
Expand All @@ -16,6 +20,7 @@ def initiate(token_addr: address, token_quantity: currency_value):
self.invariant = msg.value * token_quantity
assert self.invariant > 0

# Sells ether to the contract in exchange for tokens (minus a fee)
@public
@payable
def eth_to_tokens():
Expand All @@ -28,6 +33,7 @@ def eth_to_tokens():
self.total_eth_qty = new_total_eth
self.total_token_qty = new_total_tokens

# Sells tokens to the contract in exchange for ether
@public
def tokens_to_eth(sell_quantity: currency_value):
self.token_address.transferFrom(msg.sender, self, as_num256(sell_quantity))
Expand All @@ -38,6 +44,7 @@ def tokens_to_eth(sell_quantity: currency_value):
self.total_eth_qty = new_total_eth
self.total_token_qty = new_total_tokens

# Owner can withdraw their funds and destroy the market maker
@public
def owner_withdraw():
assert self.owner == msg.sender
Expand Down

0 comments on commit 1281fd2

Please sign in to comment.