-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwallet.vy
187 lines (156 loc) · 3.69 KB
/
wallet.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# Author: Sören Steiger, github.com/ssteiger
# License: MIT
contract ERC1820Registry:
def setInterfaceImplementer(
_addr: address,
_interfaceHash: bytes32,
_implementer: address
): modifying
contract ERC20Token:
def transfer(
_to: address,
_value: uint256
) -> bool: modifying
contract ERC721Token:
def safeTransferFrom(
_from: address,
_to: address,
_tokenId: uint256,
_data: bytes[256]
): modifying
contract ERC777Token:
def send(
_to: address,
_amount: uint256,
_data: bytes[256]
): modifying
ETHReceived: event({
_from: address,
_amount: wei_value
})
ETHSent: event({
_to: address,
_amount: uint256
})
# TODO:
#ERC20Received: event({
#})
ERC20Sent: event({
_token: address,
_to: address,
_amount: uint256
})
ERC721Received: event({
_token: address,
_from: address,
_tokenId: uint256,
_data: bytes32
})
ERC721Sent: event({
_token: address,
_from: address,
_to: address,
_tokenId: uint256,
_data: bytes[256]
})
ERC777Received: event({
_operator: indexed(address),
_from: indexed(address),
_to: indexed(address),
_amount: uint256,
_data: bytes[256],
_operatorData: bytes[256]
})
ERC777Sent: event({
_operator: indexed(address),
_from: indexed(address),
_to: indexed(address),
_amount: uint256,
_data: bytes[256],
_operatorData: bytes[256]
})
erc1820Registry: ERC1820Registry
erc1820RegistryAddress: constant(address) = 0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24
owner: public(address)
@public
def __init__():
self.owner = msg.sender
self.erc1820Registry = ERC1820Registry(erc1820RegistryAddress)
self.erc1820Registry.setInterfaceImplementer(self, keccak256("ERC777TokensRecipient"), self)
self.erc1820Registry.setInterfaceImplementer(self, keccak256("ERC777TokensSender"), self)
# ----- ETH -----
@public
@payable
def __default__():
log.ETHReceived(msg.sender, msg.value)
@public
def sendETH(
_to: address,
_amount: uint256
):
assert msg.sender == self.owner
send(_to, _amount)
log.ETHSent(_to, _amount)
# ----- ERC20 -----
@public
def sendERC20(
_token: address,
_to: address,
_amount: uint256
):
assert msg.sender == self.owner
ERC20Token(_token).transfer(_to, _amount)
log.ERC20Sent(_token, _to, _amount)
#@public
#def onERC20Received():
# ----- ERC721 -----
@public
def sendERC721(
_token: address,
_to: address,
_tokenId: uint256,
_data: bytes[256]=""
):
assert msg.sender == self.owner
ERC721Token(_token).safeTransferFrom(self, _to, _tokenId, _data)
log.ERC721Sent(_token, self, _to, _tokenId, _data)
@public
def onERC721Received(
_token: address,
_from: address,
_tokenId: uint256,
_data: bytes32
) -> bytes32:
log.ERC721Received(_token, _from, _tokenId, _data)
# TODO: need to return bytes4
return keccak256("onERC721Received(address,address,uint256,bytes)")
# ----- ERC777 -----
@public
def sendERC777(
_token: address,
_to: address,
_amount: uint256,
_data: bytes[256]=""
):
assert msg.sender == self.owner
ERC777Token(_token).send(_to, _amount, _data)
@public
def tokensToSend(
_operator: address,
_from: address,
_to: address,
_amount: uint256,
_data: bytes[256],
_operatorData: bytes[256]
):
log.ERC777Sent(_operator, _from, _to, _amount, _data, _operatorData)
@public
def tokensReceived(
_operator: address,
_from: address,
_to: address,
_amount: uint256,
_data: bytes[256],
_operatorData: bytes[256]
):
log.ERC777Received(_operator, _from, _to, _amount, _data, _operatorData)