Wallet
This wallet contract is capable of receiving, holding and sending Ether as well as tokens that comply with one of the following standards:

Implementation in Vyper

Deploying

The wallet contract accesses the ERC1820Registry contract in its constructor. It is therefore necessary that the ERC1820Registry contract exists on the (test) network to where the wallet contract gets deployed.
In migrations/1_initial_migration.js a check is performed to determine if the ERC1820Registry contract exists - if it doesn't it is deployed.
wallet.vy
1
# Author: Sören Steiger, twitter.com/ssteiger_
2
# License: MIT
3
4
contract ERC1820Registry:
5
def setInterfaceImplementer(
6
_addr: address,
7
_interfaceHash: bytes32,
8
_implementer: address
9
): modifying
10
11
contract ERC20Token:
12
def transfer(
13
_to: address,
14
_value: uint256
15
) -> bool: modifying
16
17
contract ERC721Token:
18
def safeTransferFrom(
19
_from: address,
20
_to: address,
21
_tokenId: uint256,
22
_data: bytes[256]
23
): modifying
24
25
contract ERC777Token:
26
def send(
27
_to: address,
28
_amount: uint256,
29
_data: bytes[256]
30
): modifying
31
32
33
ETHReceived: event({
34
_from: address,
35
_amount: wei_value
36
})
37
38
ETHSent: event({
39
_to: address,
40
_amount: uint256
41
})
42
43
# TODO:
44
#ERC20Received: event({
45
#})
46
47
ERC20Sent: event({
48
_token: address,
49
_to: address,
50
_amount: uint256
51
})
52
53
ERC721Received: event({
54
_token: address,
55
_from: address,
56
_tokenId: uint256,
57
_data: bytes32
58
})
59
60
ERC721Sent: event({
61
_token: address,
62
_from: address,
63
_to: address,
64
_tokenId: uint256,
65
_data: bytes[256]
66
})
67
68
ERC777Received: event({
69
_operator: indexed(address),
70
_from: indexed(address),
71
_to: indexed(address),
72
_amount: uint256,
73
_data: bytes[256],
74
_operatorData: bytes[256]
75
})
76
77
ERC777Sent: event({
78
_operator: indexed(address),
79
_from: indexed(address),
80
_to: indexed(address),
81
_amount: uint256,
82
_data: bytes[256],
83
_operatorData: bytes[256]
84
})
85
86
87
erc1820Registry: ERC1820Registry
88
erc1820RegistryAddress: constant(address) = 0x1820a4B7618BdE71Dce8cdc73aAB6C95905faD24
89
90
owner: public(address)
91
92
93
@public
94
def __init__():
95
self.owner = msg.sender
96
self.erc1820Registry = ERC1820Registry(erc1820RegistryAddress)
97
self.erc1820Registry.setInterfaceImplementer(self, keccak256("ERC777TokensRecipient"), self)
98
self.erc1820Registry.setInterfaceImplementer(self, keccak256("ERC777TokensSender"), self)
99
100
101
# ----- ETH -----
102
@public
103
@payable
104
def __default__():
105
log.ETHReceived(msg.sender, msg.value)
106
107
@public
108
def sendETH(
109
_to: address,
110
_amount: uint256
111
):
112
assert msg.sender == self.owner
113
send(_to, _amount)
114
log.ETHSent(_to, _amount)
115
116
117
# ----- ERC20 -----
118
@public
119
def sendERC20(
120
_token: address,
121
_to: address,
122
_amount: uint256
123
):
124
assert msg.sender == self.owner
125
ERC20Token(_token).transfer(_to, _amount)
126
log.ERC20Sent(_token, _to, _amount)
127
128
#@public
129
#def onERC20Received():
130
131
132
# ----- ERC721 -----
133
@public
134
def sendERC721(
135
_token: address,
136
_to: address,
137
_tokenId: uint256,
138
_data: bytes[256]=""
139
):
140
assert msg.sender == self.owner
141
ERC721Token(_token).safeTransferFrom(self, _to, _tokenId, _data)
142
log.ERC721Sent(_token, self, _to, _tokenId, _data)
143
144
@public
145
def onERC721Received(
146
_token: address,
147
_from: address,
148
_tokenId: uint256,
149
_data: bytes32
150
) -> bytes32:
151
log.ERC721Received(_token, _from, _tokenId, _data)
152
# TODO: need to return bytes4
153
return keccak256("onERC721Received(address,address,uint256,bytes)")
154
155
156
# ----- ERC777 -----
157
@public
158
def sendERC777(
159
_token: address,
160
_to: address,
161
_amount: uint256,
162
_data: bytes[256]=""
163
):
164
assert msg.sender == self.owner
165
ERC777Token(_token).send(_to, _amount, _data)
166
167
@public
168
def tokensToSend(
169
_operator: address,
170
_from: address,
171
_to: address,
172
_amount: uint256,
173
_data: bytes[256],
174
_operatorData: bytes[256]
175
):
176
log.ERC777Sent(_operator, _from, _to, _amount, _data, _operatorData)
177
178
@public
179
def tokensReceived(
180
_operator: address,
181
_from: address,
182
_to: address,
183
_amount: uint256,
184
_data: bytes[256],
185
_operatorData: bytes[256]
186
):
187
log.ERC777Received(_operator, _from, _to, _amount, _data, _operatorData)
188
Copied!
Last modified 2yr ago