Class: ERC20
- Inherits:
-
Contract
show all
- Defined in:
- lib/uniswap/ERC20.rb
Overview
Instance Method Summary
collapse
Instance Method Details
#_burn(from:, amount:) ⇒ Object
73
74
75
76
77
78
|
# File 'lib/uniswap/ERC20.rb', line 73
def _burn( from:, amount: )
@balanceOf[from] -= amount
@totalSupply -= amount
log Transfer, from: from, to: address(0), amount: amount
end
|
#_mint(to:, amount:) ⇒ Object
65
66
67
68
69
70
|
# File 'lib/uniswap/ERC20.rb', line 65
def _mint( to:, amount: )
@totalSupply += amount
@balanceOf[to] += amount
log Transfer, from: address(0), to: to, amount: amount
end
|
#approve(spender:, amount:) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/uniswap/ERC20.rb', line 27
def approve( spender:, amount: )
@allowance[msg.sender][spender] = amount
log Approval, owner: msg.sender, spender: spender, amount: amount
true
end
|
#constructor(name:, symbol:, decimals:) ⇒ Object
20
21
22
23
24
|
# File 'lib/uniswap/ERC20.rb', line 20
def constructor(name:, symbol:, decimals:)
@name = name
@symbol = symbol
@decimals = decimals
end
|
#transfer(to:, amount:) ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/uniswap/ERC20.rb', line 36
def transfer( to:, amount: )
assert @balanceOf[msg.sender] >= amount, "Insufficient balance"
@balanceOf[msg.sender] -= amount
@balanceOf[to] += amount
log Transfer, from: msg.sender, to: to, amount: amount
true
end
|
#transferFrom(from:, to:, amount:) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/uniswap/ERC20.rb', line 48
def transferFrom( from:, to:, amount: )
allowed = @allowance[from][msg.sender]
assert @balanceOf[from] >= amount, "Insufficient balance"
assert allowed >= amount, "Insufficient allowance"
@allowance[from][msg.sender] = allowed - amount
@balanceOf[from] -= amount
@balanceOf[to] += amount
log Transfer, from: from, to: to, amount: amount
true
end
|