Skip to content

Commit 3d17b94

Browse files
authored
docs: Add documentation (#47)
1 parent 8bc50a4 commit 3d17b94

7 files changed

+495
-49
lines changed

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ deployments
1212
broadcast
1313
!/broadcast/*/1/
1414

15-
# Docs
16-
docs/
17-
1815
# Dotenv file
1916
.env
2017

CODE_OF_CONDUCT.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to make participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies within all project spaces, and it also applies when
49+
an individual is representing the project or its community in public spaces.
50+
Examples of representing a project or community include using an official
51+
project e-mail address, posting via an official social media account, or acting
52+
as an appointed representative at an online or offline event. Representation of
53+
a project may be further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at <contact@storyprotocol.xyz>. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at <https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
<https://www.contributor-covenant.org/faq>

CONTRIBUTING.md

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
# Contributing
2+
3+
## Code of Conduct
4+
Please make sure to read and observe our [Code of Conduct](/CODE_OF_CONDUCT.md).
5+
6+
## Bug Reports
7+
8+
* Ensure your issue [has not already been reported][1]. It may already be fixed!
9+
* Include the steps you carried out to produce the problem.
10+
* Include the behavior you observed along with the behavior you expected, and
11+
why you expected it.
12+
* Include any relevant traces or debugging output.
13+
14+
## Feature Requests
15+
16+
We welcome feedback with or without pull requests. If you have an idea for how
17+
to improve the project, great! All we ask is that you take the time to write a
18+
clear and concise explanation of what need you are trying to solve. If you have
19+
thoughts on _how_ it can be solved, include those too!
20+
21+
The best way to see a feature added, however, is to submit a pull request.
22+
23+
## Pull requests
24+
25+
Pull requests are squash-merged to keep the `main` branch history clean. The title of the pull request becomes the commit message, so it should be written in a consistent format:
26+
27+
1) Begin with a capital letter.
28+
2) Do not end with a period.
29+
3) Write in the imperative: "Add feature X" and not "Adds feature X" or "Added feature X".
30+
31+
We welcome conventional commits, with prefixes the title with "fix:" or "feat:".
32+
33+
Work in progress pull requests should be submitted as Drafts and should **not** be prefixed with "WIP:".
34+
35+
Branch names don't matter, and commit messages within a pull request mostly don't matter either, although they can help the review process.
36+
37+
## Find something to work on
38+
39+
We are always in need of help, be it fixing documentation, reporting bugs or writing some code.
40+
Look at places where you feel best coding practices aren't followed, code refactoring is needed or tests are missing.
41+
42+
If you have questions about the development process,
43+
feel free to [file an issue](https://github.com/storyprotocol/protocol-periphery-v1/issues/new).
44+
45+
## Engineering Guidelines
46+
47+
### Testing
48+
49+
Code must be thoroughly tested with quality unit tests.
50+
51+
We defer to the [Foundry Best Practices](https://book.getfoundry.sh/tutorials/best-practices) and [Moloch Testing Guide](https://github.com/MolochVentures/moloch/tree/master/test#readme) for specific recommendations, though not all of it is relevant here. Note the introduction in Moloch Testing Guide:
52+
53+
> Tests should be written, not only to verify correctness of the target code, but to be comprehensively reviewed by other programmers. Therefore, for mission critical Solidity code, the quality of the tests are just as important (if not more so) than the code itself, and should be written with the highest standards of clarity and elegance.
54+
55+
Every addition or change to the code must come with relevant and comprehensive tests.
56+
57+
Flaky tests are not acceptable.
58+
59+
The test suite should run automatically for every change in the repository, and in pull requests tests must pass before merging.
60+
61+
The test suite coverage must be kept as close to 100% as possible, enforced in pull requests.
62+
63+
Test should use Foundry, unless for some reason js or hardhat are needed (for example, upgrades).
64+
65+
The test function names will follow
66+
67+
```
68+
- test_contextCamel_descriptionOfTheTestCamel
69+
- context = method name, contract or functionality.
70+
```
71+
72+
In some cases unit tests may be insufficient and complementary techniques should be used:
73+
74+
1. Property-based tests (aka. fuzzing) for math-heavy code.
75+
2. hardhat test using `hardhat-upgrades` OZ plugin to verify storage and upgradeability (until they support Foundry).
76+
3. Fork tests for upgreadeability to new implementations for upgradeable contracts, testing against the deployed contracts.
77+
4. E2E tests for critical (happy) paths.
78+
5. Formal verification for state machines.
79+
80+
### Documentation
81+
82+
For contributors, project guidelines and processes must be documented publicly.
83+
84+
Every method and contract must have Natspec, using the `///` flavour always.
85+
86+
For users, features must be abundantly documented. Documentation should include answers to common questions, solutions to common problems, and recommendations for critical decisions that the user may face.
87+
88+
All changes to the core codebase (excluding tests, auxiliary scripts, etc.) must be documented in a changelog, except for purely cosmetic or documentation changes.
89+
90+
### Peer review
91+
92+
All changes must be submitted through pull requests and go through peer code review.
93+
94+
The review must be approached by the reviewer in a similar way as if it was an audit of the code in question (but importantly it is not a substitute for and should not be considered an audit).
95+
96+
Reviewers should enforce code and project guidelines.
97+
98+
External contributions must be reviewed separately by multiple maintainers.
99+
100+
### Automation
101+
102+
Automation should be used as much as possible to reduce the possibility of human error and forgetfulness.
103+
104+
Automations that make use of sensitive credentials must use secure secret management, and must be strengthened against attacks such as [those on GitHub Actions worklows](https://github.com/nikitastupin/pwnhub).
105+
106+
Some other examples of automation are:
107+
108+
- Looking for common security vulnerabilities or errors in our code (eg. reentrancy analysis).
109+
- Keeping dependencies up to date and monitoring for vulnerable dependencies.
110+
111+
### Code style
112+
113+
Solidity code should be written in a consistent format enforced by a linter, following the official [Solidity Style Guide](https://docs.soliditylang.org/en/latest/style-guide.html). See below for further [Solidity Conventions](#solidity-conventions).
114+
115+
The code should be simple and straightforward, prioritizing readability and understandability. Consistency and predictability should be maintained across the codebase. In particular, this applies to naming, which should be systematic, clear, and concise.
116+
117+
Sometimes these guidelines may be broken if doing so brings significant efficiency gains, but explanatory comments should be added.
118+
119+
Modularity should be pursued, but not at the cost of the above priorities.
120+
121+
### Solidity Conventions
122+
123+
In addition to the official Solidity Style Guide we have a number of other conventions that must be followed.
124+
125+
- Minimize exposing state variables, unless they help with external systems integration or readability.
126+
127+
- Changes to state should be accompanied by events, and in some cases it is not correct to arbitrarily set state.
128+
129+
- Internal or private state variables or functions should have an underscore prefix.
130+
131+
```solidity
132+
contract TestContract {
133+
uint256 private _privateVar;
134+
uint256 internal _internalVar;
135+
function _testInternal() internal { ... }
136+
function _testPrivate() private { ... }
137+
}
138+
```
139+
140+
* constant or immutable variables must be ALL_CAPS with underscores._ALL_CAPS if private or internal.
141+
142+
- Events should be emitted immediately after the state change that they
143+
represent, and should be named in the past tense.
144+
145+
```solidity
146+
function _burn(address who, uint256 value) internal {
147+
super._burn(who, value);
148+
emit TokensBurned(who, value);
149+
}
150+
```
151+
152+
Some standards (e.g. ERC20) use present tense, and in those cases the
153+
standard specification is used.
154+
155+
- Interface names should have a capital I prefix.
156+
157+
```solidity
158+
interface IERC777 {
159+
```
160+
161+
- Group contracts by functionality within folders if possible.
162+
163+
- Interfaces should go inside the `interface` folder, mirroring the folder structure of the implementations
164+
165+
- Folder names must be lowercase, hyphen separated.
166+
167+
```
168+
example-folder
169+
```
170+
171+
- Contract names must be camel case, starting with uppercase letter
172+
173+
```
174+
ExampleContract.sol
175+
```
176+
177+
- Acronyms should be
178+
- Uppercase all if in contract name (`UUPSUpgradeable`, `IPAsset`)
179+
- Camelcase in properties and function names (`ipAssetId`), except if they are defined otherwise in external contracts or interfaces (`tokenURI`)
180+
181+
- Unchecked arithmetic blocks should contain comments explaining why overflow is guaranteed not to happen. If the reason is immediately apparent from the line above the unchecked block, the comment may be omitted.
182+
183+
- Interfaces should contain methods an events. Structs showing in an interface should be grouped in a library
184+
185+
- Function parameter names will have the **suffix** `_`
186+
187+
- Naming conventions
188+
189+
- Contract: CamelCase (adjectiveNoun)
190+
- Struct (noun)
191+
- Event (past-tense)
192+
- Function Name (verb noun)
193+
- local variable (noun / compound noun)
194+
- Booleans (use `isXXX`)
195+
- `isValid`
196+
- `valid`
197+
- Modifier (prepositionNoun)
198+
- `onlyOwner`
199+
200+
201+
[1]: https://github.com/storyprotocol/protocol-periphery-v1/issues

0 commit comments

Comments
 (0)