Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update l0k_erc20.cairo #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 20 additions & 79 deletions contracts/l0k_erc20.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,118 +2,59 @@

%lang starknet

from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.cairo.common.uint256 import Uint256
from starkware.cairo.common.bool import TRUE
from starkware.starknet.common.syscalls import get_caller_address

from openzeppelin.token.erc20.library import ERC20

@constructor
func constructor{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
name : felt, symbol : felt
):
let (owner) = get_caller_address()
func constructor(name: felt, symbol: felt):
let owner = get_caller_address()
ERC20.initializer(name, symbol, 18)
return ()
end

#
# Getters
#

@view
func name{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}() -> (name : felt):
let (name) = ERC20.name()
return (name)
end
func name() -> felt:
return ERC20.name()

@view
func symbol{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}() -> (symbol : felt):
let (symbol) = ERC20.symbol()
return (symbol)
end
func symbol() -> felt:
return ERC20.symbol()

@view
func totalSupply{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}() -> (
totalSupply : Uint256
):
let (totalSupply) = ERC20.total_supply()
return (totalSupply)
end
func totalSupply() -> felt:
return ERC20.total_supply().val

@view
func decimals{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}() -> (
decimals : felt
):
let (decimals) = ERC20.decimals()
return (decimals)
end
func decimals() -> felt:
return ERC20.decimals()

@view
func balanceOf{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
account : felt
) -> (balance : Uint256):
let (balance) = ERC20.balance_of(account)
return (balance)
end
func balanceOf(account: felt) -> felt:
return ERC20.balance_of(account).val

@view
func allowance{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
owner : felt, spender : felt
) -> (remaining : Uint256):
let (remaining) = ERC20.allowance(owner, spender)
return (remaining)
end

#
# Externals
#
func allowance(owner: felt, spender: felt) -> felt:
return ERC20.allowance(owner, spender).val

@external
func transfer{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
recipient : felt, amount : Uint256
) -> (success : felt):
func transfer(recipient: felt, amount: felt):
ERC20.transfer(recipient, amount)
return (TRUE)
end

@external
func transferFrom{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
sender : felt, recipient : felt, amount : Uint256
) -> (success : felt):
func transferFrom(sender: felt, recipient: felt, amount: felt):
ERC20.transfer_from(sender, recipient, amount)
return (TRUE)
end

@external
func approve{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
spender : felt, amount : Uint256
) -> (success : felt):
func approve(spender: felt, amount: felt):
ERC20.approve(spender, amount)
return (TRUE)
end

@external
func increaseAllowance{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
spender : felt, added_value : Uint256
) -> (success : felt):
func increaseAllowance(spender: felt, added_value: felt):
ERC20.increase_allowance(spender, added_value)
return (TRUE)
end

@external
func decreaseAllowance{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
spender : felt, subtracted_value : Uint256
) -> (success : felt):
func decreaseAllowance(spender: felt, subtracted_value: felt):
ERC20.decrease_allowance(spender, subtracted_value)
return (TRUE)
end

@external
func mint{syscall_ptr : felt*, pedersen_ptr : HashBuiltin*, range_check_ptr}(
to : felt, amount : Uint256
):
func mint(to: felt, amount: felt):
ERC20._mint(to, amount)
return ()
end