diff --git a/examples/market_maker/on_chain_market_maker.v.py b/examples/market_maker/on_chain_market_maker.v.py index c5150bd00a..69adb1a200 100644 --- a/examples/market_maker/on_chain_market_maker.v.py +++ b/examples/market_maker/on_chain_market_maker.v.py @@ -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): @@ -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(): @@ -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)) @@ -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