Sha256: 9f04e5db3f94651bd436a0efabd8c6fc8d8fc1f22eaea36fb3e5da2c8108ff1d
Contents?: true
Size: 1.96 KB
Versions: 2
Compression:
Stored size: 1.96 KB
Contents
class ERC20 < Contract # abstract: true event :Transfer, from: Address, to: Address, amount: UInt event :Approval, owner: Address, spender: Address, amount: UInt storage name: String, symbol: String, decimals: UInt, totalSupply: UInt, balanceOf: mapping( Address, UInt), allowance: mapping( Address, mapping( Address, UInt)) sig [String, String, UInt] def constructor(name:, symbol:, decimals:) @name = name @symbol = symbol @decimals = decimals end sig [Address, UInt], returns: Bool def approve( spender:, amount: ) @allowance[msg.sender][spender] = amount log Approval, owner: msg.sender, spender: spender, amount: amount true end sig [Address, UInt], returns: Bool 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 sig [Address, Address, UInt], returns: Bool 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 sig [Address, UInt] def _mint( to:, amount: ) @totalSupply += amount @balanceOf[to] += amount log Transfer, from: address(0), to: to, amount: amount end sig [Address, UInt] def _burn( from:, amount: ) @balanceOf[from] -= amount @totalSupply -= amount log Transfer, from: from, to: address(0), amount: amount end end # class ERC20
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
uniswap-0.1.0 | lib/uniswap/ERC20.rb |
uniswap-0.0.1 | lib/uniswap/ERC20.rb |