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

Refactor directory structure #350

Merged
merged 30 commits into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6294925
add lib and preset dirs
andrew-fleming May 31, 2022
d154923
remove underscore from names, finish init reorganization
andrew-fleming May 31, 2022
850030a
fix mock names, adjusted paths
andrew-fleming Jun 1, 2022
751ea89
update branch Merge branch 'main' of https://github.com/andrew-flemin…
andrew-fleming Jun 1, 2022
eec911c
update paths in tests
andrew-fleming Jun 1, 2022
ad2b4ab
update attribution
andrew-fleming Jun 1, 2022
208a673
Rename safemath.cairo to SafeMath.cairo
andrew-fleming Jun 1, 2022
05b78a3
Rename initializable.cairo to Initializable.cairo
andrew-fleming Jun 1, 2022
ea9966f
Rename pausable.cairo to Pausable.cairo
andrew-fleming Jun 1, 2022
9588959
update version in attribution
andrew-fleming Jun 3, 2022
845ac1b
update branch Merge branch 'main' of https://github.com/andrew-flemin…
andrew-fleming Jun 13, 2022
3396b07
update branch Merge branch 'main' of https://github.com/andrew-flemin…
andrew-fleming Jun 15, 2022
1a6a6a5
update branch, fix paths
andrew-fleming Jun 17, 2022
a88af6a
add conventions to CONTRIBUTING.md
andrew-fleming Jun 17, 2022
3de6caa
update names and paths in docs
andrew-fleming Jun 18, 2022
87dc199
fix paths in code snippets
andrew-fleming Jun 18, 2022
b0d59f8
rename libs to lib
andrew-fleming Jul 14, 2022
2d03060
Apply suggestions from code review
andrew-fleming Jul 14, 2022
66fc6c4
Update CONTRIBUTING.md
andrew-fleming Jul 14, 2022
cc573e5
update link paths
andrew-fleming Jul 14, 2022
58fb80d
update structure
andrew-fleming Jul 14, 2022
0128e7e
fix compilation msg and import snippet
andrew-fleming Jul 15, 2022
d849fde
update branch
andrew-fleming Jul 15, 2022
cc9ccfb
Apply suggestions from code review
andrew-fleming Jul 15, 2022
a551c45
fix paths, move ERC721Holder
andrew-fleming Jul 15, 2022
7686794
remove upgrades dir
andrew-fleming Jul 16, 2022
8a22da1
fix pin
andrew-fleming Jul 17, 2022
1984e9d
update branch
andrew-fleming Jul 20, 2022
5cd09ad
update paths for proxy
andrew-fleming Jul 22, 2022
678093f
update links and code block imports
andrew-fleming Jul 23, 2022
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
28 changes: 27 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,33 @@ Before starting development, please [create an issue](https://github.com/OpenZep

Also, consider that snake case is used for Cairo development in general due to its strong Python bias, but in order to be compliant with the standards, EIP implementations must use camelCase. Therefore, EIP-based contracts will have their external functions written in camelCase while the rest of the codebase will be in snake_case.

And make sure to always include tests and documentation for the new developments.
And make sure to always include tests and documentation for the new developments. Please consider the following conventions:

- Naming
- libraries should be named `library.cairo`, e.g. `erc20/library.cairo`
- contracts should be PascalCased i.e. `MyContract.cairo`
- interfaces should be prefixed with an `I`, as in `IAccount.cairo`
- test modules should begin with `test_` followed by the contract name i.e. `test_MyContract.py`

- Structure
- libraries should cede their names to their parent directory and are named `library.cairo` instead
- interfaces should be alongside the library that the interface defines
- preset contracts should be within a `presets` directory of the library to which they are a preset
- Here are example paths:
- `openzeppelin.token.erc20.library`
- `openzeppelin.token.erc20.IERC20`
- `openzeppelin.token.erc20.presets.ERC20Mintable`
- And a visual guide:

```python
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why python?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linter expects a language with the code block. Python is an arbitrary solution since this is just a visual aid

openzeppelin
└──token
└── erc20
├── library.cairo
├── IERC20.cairo
└── presets
└── ERC20Mintable.cairo
```

## Creating Pull Requests (PRs)

Expand Down
60 changes: 33 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ nile deploy MyToken <name> <symbol> <decimals> <initial_supply> <recipient> --al

from starkware.cairo.common.cairo_builtins import HashBuiltin
from starkware.cairo.common.uint256 import Uint256
from openzeppelin.security.pausable import Pausable
from openzeppelin.security.pausable.library import Pausable
from openzeppelin.token.erc20.library import ERC20

(...)
Expand Down Expand Up @@ -148,32 +148,38 @@ python -m pip install .
```bash
nile compile --directory src

🤖 Compiling all Cairo contracts in the openzeppelin directory
🔨 Compiling openzeppelin/introspection/ERC165.cairo
🔨 Compiling openzeppelin/introspection/IERC165.cairo
🔨 Compiling openzeppelin/token/erc721/ERC721_Mintable_Burnable.cairo
🔨 Compiling openzeppelin/token/erc721/ERC721_Mintable_Pausable.cairo
🔨 Compiling openzeppelin/token/erc721/library.cairo
🔨 Compiling openzeppelin/token/erc721/interfaces/IERC721_Metadata.cairo
🔨 Compiling openzeppelin/token/erc721/interfaces/IERC721.cairo
🔨 Compiling openzeppelin/token/erc721/interfaces/IERC721_Receiver.cairo
🔨 Compiling openzeppelin/token/erc721/utils/ERC721_Holder.cairo
🔨 Compiling openzeppelin/token/erc20/ERC20_Mintable.cairo
🔨 Compiling openzeppelin/token/erc20/ERC20.cairo
🔨 Compiling openzeppelin/token/erc20/library.cairo
🔨 Compiling openzeppelin/token/erc20/ERC20_Pausable.cairo
🔨 Compiling openzeppelin/token/erc20/interfaces/IERC20.cairo
🔨 Compiling openzeppelin/token/erc721_enumerable/ERC721_Enumerable_Mintable_Burnable.cairo
🔨 Compiling openzeppelin/token/erc721_enumerable/library.cairo
🔨 Compiling openzeppelin/token/erc721_enumerable/interfaces/IERC721_Enumerable.cairo
🔨 Compiling openzeppelin/security/pausable.cairo
🔨 Compiling openzeppelin/security/safemath.cairo
🔨 Compiling openzeppelin/security/initializable.cairo
🔨 Compiling openzeppelin/access/ownable.cairo
🔨 Compiling openzeppelin/account/IAccount.cairo
🔨 Compiling openzeppelin/account/Account.cairo
🔨 Compiling openzeppelin/account/AddressRegistry.cairo
🔨 Compiling openzeppelin/utils/constants.cairo
🤖 Compiling all Cairo contracts in the src directory
🔨 Compiling src/openzeppelin/token/erc20/library.cairo
🔨 Compiling src/openzeppelin/token/erc20/presets/ERC20Mintable.cairo
🔨 Compiling src/openzeppelin/token/erc20/presets/ERC20Pausable.cairo
🔨 Compiling src/openzeppelin/token/erc20/presets/ERC20Upgradeable.cairo
🔨 Compiling src/openzeppelin/token/erc20/presets/ERC20.cairo
🔨 Compiling src/openzeppelin/token/erc20/IERC20.cairo
🔨 Compiling src/openzeppelin/token/erc721/enumerable/library.cairo
🔨 Compiling src/openzeppelin/token/erc721/library.cairo
🔨 Compiling src/openzeppelin/token/erc721/utils/ERC721Holder.cairo
🔨 Compiling src/openzeppelin/token/erc721/presets/ERC721MintablePausable.cairo
🔨 Compiling src/openzeppelin/token/erc721/presets/ERC721MintableBurnable.cairo
🔨 Compiling src/openzeppelin/token/erc721/presets/ERC721EnumerableMintableBurnable.cairo
🔨 Compiling src/openzeppelin/token/erc721/IERC721.cairo
🔨 Compiling src/openzeppelin/token/erc721/IERC721Metadata.cairo
🔨 Compiling src/openzeppelin/token/erc721/IERC721Receiver.cairo
🔨 Compiling src/openzeppelin/token/erc721/enumerable/IERC721Enumerable.cairo
🔨 Compiling src/openzeppelin/access/ownable/library.cairo
🔨 Compiling src/openzeppelin/security/reentrancyguard/library.cairo
🔨 Compiling src/openzeppelin/security/safemath/library.cairo
🔨 Compiling src/openzeppelin/security/pausable/library.cairo
🔨 Compiling src/openzeppelin/security/initializable/library.cairo
🔨 Compiling src/openzeppelin/utils/constants/library.cairo
🔨 Compiling src/openzeppelin/introspection/erc165/library.cairo
🔨 Compiling src/openzeppelin/introspection/erc165/IERC165.cairo
🔨 Compiling src/openzeppelin/upgrades/library.cairo
🔨 Compiling src/openzeppelin/upgrades/presets/Proxy.cairo
🔨 Compiling src/openzeppelin/account/library.cairo
🔨 Compiling src/openzeppelin/account/presets/EthAccount.cairo
🔨 Compiling src/openzeppelin/account/presets/Account.cairo
🔨 Compiling src/openzeppelin/account/presets/AddressRegistry.cairo
🔨 Compiling src/openzeppelin/account/IAccount.cairo
✅ Done
```

Expand Down
4 changes: 2 additions & 2 deletions docs/Account.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,11 @@ The following contract presets are ready to deploy and can be used as-is for qui

### Account

The [`Account`](../src/openzeppelin/account/Account.cairo) preset uses StarkNet keys to validate transactions.
The [`Account`](../src/openzeppelin/account/presets/Account.cairo) preset uses StarkNet keys to validate transactions.

### Eth Account

The [`EthAccount`](../src/openzeppelin/account/EthAccount.cairo) preset supports Ethereum addresses, validating transactions with secp256k1 keys.
The [`EthAccount`](../src/openzeppelin/account/presets/EthAccount.cairo) preset supports Ethereum addresses, validating transactions with secp256k1 keys.

## Account differentiation with ERC165

Expand Down
28 changes: 14 additions & 14 deletions docs/ERC20.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ The ERC20 token standard is a specification for [fungible tokens](https://docs.o
- [Extensibility](#extensibility)
- [Presets](#presets)
- [ERC20 (basic)](#erc20-basic)
- [ERC20_Mintable](#erc20_mintable)
- [ERC20_Pausable](#erc20_pausable)
- [ERC20_Upgradeable](#erc20_upgradeable)
- [ERC20Mintable](#erc20mintable)
- [ERC20Pausable](#erc20pausable)
- [ERC20Upgradeable](#erc20upgradeable)
Comment on lines +13 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what a lovely race condition with #396

- [API Specification](#api-specification)
- [Methods](#methods)
- [`name`](#name)
Expand Down Expand Up @@ -100,7 +100,7 @@ To create a token you need to deploy it like this:

```python
erc20 = await starknet.deploy(
"contracts/token/ERC20.cairo",
"openzeppelin/token/erc20/presets/ERC20.cairo",
constructor_calldata=[
str_to_felt("Token"), # name
str_to_felt("TKN"), # symbol
Expand All @@ -127,7 +127,7 @@ await signer.send_transaction(account, erc20.contract_address, 'transfer', [reci

## Extensibility

ERC20 contracts can be extended by following the [extensibility pattern](../docs/Extensibility.md#the-pattern). The basic idea behind integrating the pattern is to import the requisite ERC20 methods from the ERC20 library and incorporate the extended logic thereafter. For example, let's say you wanted to implement a pausing mechanism. The contract should first import the ERC20 methods and the extended logic from the [pausable library](../src/openzeppelin/security/pausable.cairo) i.e. `Pausable_pause`, `Pausable_unpause`. Next, the contract should expose the methods with the extended logic therein like this:
ERC20 contracts can be extended by following the [extensibility pattern](../docs/Extensibility.md#the-pattern). The basic idea behind integrating the pattern is to import the requisite ERC20 methods from the ERC20 library and incorporate the extended logic thereafter. For example, let's say you wanted to implement a pausing mechanism. The contract should first import the ERC20 methods and the extended logic from the [pausable library](../src/openzeppelin/security/pausable/library.cairo) i.e. `Pausable_pause`, `Pausable_unpause`. Next, the contract should expose the methods with the extended logic therein like this:

```python
@external
Expand All @@ -136,8 +136,8 @@ func transfer{
pedersen_ptr : HashBuiltin*,
range_check_ptr
}(recipient: felt, amount: Uint256) -> (success: felt):
Pausable_when_not_paused() # imported extended logic
ERC20_transfer(recipient, amount) # imported library method
Pausable.when_not_paused() # imported extended logic
ERC20.transfer(recipient, amount) # imported library method
return (TRUE)
end
```
Expand All @@ -158,19 +158,19 @@ The following contract presets are ready to deploy and can be used as-is for qui

### ERC20 (basic)

The [`ERC20`](../src/openzeppelin/token/erc20/ERC20.cairo) preset offers a quick and easy setup for deploying a basic ERC20 token.
The [`ERC20`](../src/openzeppelin/token/erc20/presets/ERC20.cairo) preset offers a quick and easy setup for deploying a basic ERC20 token.

### ERC20_Mintable
### ERC20Mintable

The [`ERC20_Mintable`](../src/openzeppelin/token/erc20/ERC20_Mintable.cairo) preset allows the contract owner to mint new tokens.
The [`ERC20Mintable`](../src/openzeppelin/token/erc20/presets/ERC20Mintable.cairo) preset allows the contract owner to mint new tokens.

### ERC20_Pausable
### ERC20Pausable

The [`ERC20_Pausable`](../src/openzeppelin/token/erc20/ERC20_Pausable.cairo) preset allows the contract owner to pause/unpause all state-modifying methods i.e. `transfer`, `approve`, etc. This preset proves useful for scenarios such as preventing trades until the end of an evaluation period and having an emergency switch for freezing all token transfers in the event of a large bug.
The [`ERC20Pausable`](../src/openzeppelin/token/erc20/presets/ERC20Pausable.cairo) preset allows the contract owner to pause/unpause all state-modifying methods i.e. `transfer`, `approve`, etc. This preset proves useful for scenarios such as preventing trades until the end of an evaluation period and having an emergency switch for freezing all token transfers in the event of a large bug.

### ERC20_Upgradeable
### ERC20Upgradeable

The [`ERC20_Upgradeable`](../src/openzeppelin/token/erc20/ERC20_Upgradeable.cairo) preset allows the contract owner to upgrade a contract by deploying a new ERC20 implementation contract while also maintaing the contract's state. This preset proves useful for scenarios such as eliminating bugs and adding new features. For more on upgradeability, see [Contract upgrades](Proxies.md#contract-upgrades).
The [`ERC20Upgradeable`](../src/openzeppelin/token/erc20/presets/ERC20Upgradeable.cairo) preset allows the contract owner to upgrade a contract by deploying a new ERC20 implementation contract while also maintaing the contract's state. This preset proves useful for scenarios such as eliminating bugs and adding new features. For more on upgradeability, see [Contract upgrades](Proxies.md#contract-upgrades).

## API Specification

Expand Down
Loading