-
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.
* add erc20 preset * add tests * fix formatting * change preset name * tidy up tests * normalize assert msgs * simplify ZERO, add other transfer tests * add other transfer tests * add erc20 preset section * fix preset sentence * change initial_supply to fixed_supply * add code comments * move preset to API * Apply suggestions from code review Co-authored-by: Martín Triay <[email protected]> * fix preset section sentence * normalize comments --------- Co-authored-by: Martín Triay <[email protected]>
- Loading branch information
1 parent
f3e2a5f
commit 7a7be63
Showing
7 changed files
with
661 additions
and
46 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
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod account; | ||
mod erc20; | ||
|
||
use account::Account; | ||
use erc20::ERC20; |
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,55 @@ | ||
// SPDX-License-Identifier: MIT | ||
// OpenZeppelin Contracts for Cairo v0.8.0-beta.0 (presets/erc20.cairo) | ||
|
||
/// # ERC20 Preset | ||
/// | ||
/// The ERC20 contract offers basic functionality and provides a | ||
/// fixed-supply mechanism for token distribution. The fixed supply is | ||
/// set in the constructor. | ||
#[starknet::contract] | ||
mod ERC20 { | ||
use openzeppelin::token::erc20::ERC20Component; | ||
use starknet::ContractAddress; | ||
|
||
component!(path: ERC20Component, storage: erc20, event: ERC20Event); | ||
|
||
#[abi(embed_v0)] | ||
impl ERC20Impl = ERC20Component::ERC20Impl<ContractState>; | ||
#[abi(embed_v0)] | ||
impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl<ContractState>; | ||
#[abi(embed_v0)] | ||
impl SafeAllowanceImpl = ERC20Component::SafeAllowanceImpl<ContractState>; | ||
#[abi(embed_v0)] | ||
impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl<ContractState>; | ||
#[abi(embed_v0)] | ||
impl SafeAllowanceCamelImpl = | ||
ERC20Component::SafeAllowanceCamelImpl<ContractState>; | ||
impl InternalImpl = ERC20Component::InternalImpl<ContractState>; | ||
|
||
#[storage] | ||
struct Storage { | ||
#[substorage(v0)] | ||
erc20: ERC20Component::Storage | ||
} | ||
|
||
#[event] | ||
#[derive(Drop, starknet::Event)] | ||
enum Event { | ||
#[flat] | ||
ERC20Event: ERC20Component::Event | ||
} | ||
|
||
/// Sets the token `name` and `symbol`. | ||
/// Mints `fixed_supply` tokens to `recipient`. | ||
#[constructor] | ||
fn constructor( | ||
ref self: ContractState, | ||
name: felt252, | ||
symbol: felt252, | ||
fixed_supply: u256, | ||
recipient: ContractAddress | ||
) { | ||
self.erc20.initializer(name, symbol); | ||
self.erc20._mint(recipient, fixed_supply); | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
mod test_account; | ||
mod test_erc20; |
Oops, something went wrong.