-
Notifications
You must be signed in to change notification settings - Fork 2
/
Exchange.vy
45 lines (31 loc) · 1.03 KB
/
Exchange.vy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from vyper.interfaces import ERC20
interface Factory:
def register(): nonpayable
def trade(_token1: ERC20, _token2: ERC20, _amt: uint256): nonpayable
token: public(ERC20)
factory: Factory
@external
def __init__(_token: ERC20, _factory: Factory):
self.token = _token
self.factory = _factory
@external
def initialize():
# Anyone can safely call this function because of EXTCODEHASH
self.factory.register()
# NOTE: This contract restricts trading to only be done by the factory.
# A practical implementation would probably want counter-pairs
# and liquidity management features for each exchange pool.
@external
def receive(_from: address, _amt: uint256):
assert msg.sender == self.factory.address
success: bool = self.token.transferFrom(_from, self, _amt)
assert success
@external
def transfer(_to: address, _amt: uint256):
assert msg.sender == self.factory.address
success: bool = self.token.transfer(_to, _amt)
assert success
@external
@view
def returnOne() -> uint256:
return 1