-
Notifications
You must be signed in to change notification settings - Fork 594
/
Copy patherc20.vy
40 lines (32 loc) · 1.11 KB
/
erc20.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
# Minimal ERC-20 contract
balances: HashMap[address, uint256]
allowances: HashMap[address, HashMap[address, uint256]]
total_supply: uint256
@external
def balanceOf(_owner: address) -> uint256:
return self.balances[_owner]
@external
def transfer(_to: address, _value: uint256) -> bool:
assert self.balances[msg.sender] >= _value, "Insufficient balance"
self.balances[msg.sender] -= _value
self.balances[_to] += _value
return True
@external
def transferFrom(_from: address, _to: address, _value: uint256) -> bool:
assert self.balances[_from] >= _value, "Insufficient balance"
assert self.allowances[_from][msg.sender] >= _value, "Insufficient allowance"
self.allowances[_from][msg.sender] -= _value
self.balances[_from] -= _value
self.balances[_to] += _value
return True
@external
def approve(_spender: address, _value: uint256) -> bool:
self.allowances[msg.sender][_spender] = _value
return True
@external
def mint(_to: address, _value: uint256):
self.balances[_to] += _value
self.total_supply += _value
@external
def totalSupply() -> uint256:
return self.total_supply