-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
281 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
# SPDX-License-Identifier: MIT | ||
# OpenZeppelin Cairo Contracts v0.1.0 (token/erc20/ERC20_Burnable.cairo) | ||
|
||
%lang starknet | ||
|
||
from starkware.cairo.common.cairo_builtins import HashBuiltin | ||
from starkware.cairo.common.uint256 import Uint256 | ||
from starkware.starknet.common.syscalls import get_caller_address | ||
from starkware.cairo.common.bool import TRUE | ||
|
||
from openzeppelin.token.erc20.library import ERC20 | ||
|
||
from openzeppelin.access.ownable import ( | ||
Ownable_initializer, | ||
Ownable_owner, | ||
Ownable_transfer_ownership | ||
) | ||
|
||
from openzeppelin.security.safemath import uint256_checked_sub_le | ||
|
||
from openzeppelin.introspection.ERC165 import ERC165_supports_interface | ||
|
||
|
||
@constructor | ||
func constructor{ | ||
syscall_ptr : felt*, | ||
pedersen_ptr : HashBuiltin*, | ||
range_check_ptr | ||
}( | ||
name : felt, | ||
symbol : felt, | ||
decimals : felt, | ||
initial_supply : Uint256, | ||
recipient : felt, | ||
owner : felt | ||
): | ||
ERC20.constructor(name, symbol, decimals) | ||
ERC20._mint(recipient, initial_supply) | ||
Ownable_initializer(owner) | ||
return () | ||
end | ||
|
||
# | ||
# Getters | ||
# | ||
|
||
@view | ||
func name{ | ||
syscall_ptr : felt*, | ||
pedersen_ptr : HashBuiltin*, | ||
range_check_ptr | ||
}() -> (name : felt): | ||
let (name) = ERC20.name() | ||
return (name) | ||
end | ||
|
||
@view | ||
func symbol{ | ||
syscall_ptr : felt*, | ||
pedersen_ptr : HashBuiltin*, | ||
range_check_ptr | ||
}() -> (symbol : felt): | ||
let (symbol) = ERC20.symbol() | ||
return (symbol) | ||
end | ||
|
||
@view | ||
func totalSupply{ | ||
syscall_ptr : felt*, | ||
pedersen_ptr : HashBuiltin*, | ||
range_check_ptr | ||
}() -> (totalSupply : Uint256): | ||
let (totalSupply : Uint256) = ERC20.total_supply() | ||
return (totalSupply) | ||
end | ||
|
||
@view | ||
func decimals{ | ||
syscall_ptr : felt*, | ||
pedersen_ptr : HashBuiltin*, | ||
range_check_ptr | ||
}() -> (decimals : felt): | ||
let (decimals) = ERC20.decimals() | ||
return (decimals) | ||
end | ||
|
||
@view | ||
func balanceOf{ | ||
syscall_ptr : felt*, | ||
pedersen_ptr : HashBuiltin*, | ||
range_check_ptr | ||
}(account : felt) -> (balance : Uint256): | ||
let (balance : Uint256) = ERC20.balance_of(account) | ||
return (balance) | ||
end | ||
|
||
@view | ||
func allowance{ | ||
syscall_ptr : felt*, | ||
pedersen_ptr : HashBuiltin*, | ||
range_check_ptr | ||
}(owner : felt, spender : felt) -> (remaining : Uint256): | ||
let (remaining : Uint256) = ERC20.allowance(owner, spender) | ||
return (remaining) | ||
end | ||
|
||
@external | ||
func transfer{ | ||
syscall_ptr : felt*, | ||
pedersen_ptr : HashBuiltin*, | ||
range_check_ptr | ||
}(recipient : felt, amount : Uint256) -> (success : 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): | ||
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): | ||
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): | ||
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): | ||
ERC20.decrease_allowance(spender, subtracted_value) | ||
return (TRUE) | ||
end | ||
|
||
@external | ||
func burn{ | ||
syscall_ptr : felt*, | ||
pedersen_ptr : HashBuiltin*, | ||
range_check_ptr | ||
}(amount : Uint256): | ||
let (caller) = get_caller_address() | ||
ERC20._burn(caller, amount) | ||
return () | ||
end | ||
|
||
@external | ||
func burnFrom{ | ||
syscall_ptr : felt*, | ||
pedersen_ptr : HashBuiltin*, | ||
range_check_ptr | ||
}(account : felt, amount : Uint256): | ||
let (caller) = get_caller_address() | ||
ERC20._spend_allowance(account, caller, amount) | ||
ERC20._burn(account, amount) | ||
return () | ||
end | ||
|
||
@view | ||
func owner{ | ||
syscall_ptr : felt*, | ||
pedersen_ptr : HashBuiltin*, | ||
range_check_ptr | ||
}() -> (owner : felt): | ||
let (owner) = Ownable_owner.read() | ||
return (owner=owner) | ||
end | ||
|
||
@external | ||
func transferOwnership{ | ||
syscall_ptr : felt*, | ||
pedersen_ptr : HashBuiltin*, | ||
range_check_ptr | ||
}(new_owner : felt): | ||
Ownable_transfer_ownership(new_owner) | ||
return () | ||
end | ||
|
||
@external | ||
func renounceOwnership{ | ||
syscall_ptr : felt*, | ||
pedersen_ptr : HashBuiltin*, | ||
range_check_ptr | ||
}(): | ||
Ownable_transfer_ownership(0) | ||
return () | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters