- Use complete sentences and end them with the appropriate punctuation (typically a period).
- Use correct spelling.
- Use correct capitalization.
- Comments should not go past the 80th column from the start of the line. An exception can be made for multi-line math comments in Ascii or Latex.
- Add full Natspec to each contract, library, function, storage variable, struct, event, and error.
- @notice tags indicate that something is part of the public interface and should be used for giving a synopsis of a contract, public and external functions, public state variables, events and errors.
- @dev tags indicate something that developers will be interested in but isn't something that end users need to be concerned with. Each contract's Natspec should include a
@dev
section that explains the contract at a high-level and explains any gotchas that developers should be aware when integrating with or using the contracts. - Each contract must have a well-defined license.
- Each contract's Natspec should contain the full legal disclaimer.
- Integrations should include detailed comments explaining what is different or special about the implementation. This includes things like how interest accrues, why base or vault shares may not be a supported deposit or withdrawal asset, how the
convertToBase
orconvertToShares
functions work, etc. - Within function bodies, code should be broken up into logical chunks (hereafter called "comment blocks") that are clearly commented. These comments should logically explain what the block is accomplishing. Any comments interleaved within blocks should be
NOTE
orTODO
comments.- For example, this follows the rule:
Whereas this doesn’t:
// blah blah blah uint256 a = foo(); a += b - c; // NOTE: We have to reduce a because… a = a.mulDown(0.5e18);
// blah blah blah uint256 a = foo(); a += b - c; // We have to reduce a because… a = a.mulDown(0.5e18);
- For example, this follows the rule:
FIXME
comments should always be removed before merging your PR.- A
NOTE
comment should be added above any line that uses fixed point math or another function that rounds up or down to explain why the code rounds in a particular direction.
- Relative paths are preferred because they improve lookups for LSP providers.
- Imports must specify what they are importing.
- All imports must be used.
- Imports are sorted groups with absolute paths having the highest priority and relative paths having lower priority. Relative paths are grouped by the amount of leading
../
's they have (more../
have higher priority than less../
). - Imports should be sorted alphabetically.
- Each immutable should have a corresponding getter.
- Each state variable should have a corresponding getter or should be reachable through a generalized getter (like
loads
). - Each function that changes state should have an event that encodes the state changes that occurred within the function call. If possible, this event should be sufficient to fully recreate the state change that occurred from the previous state.
- Parameters should be prefaced with a leading underscore (
_
). To avoid shadowing internal or private immutable or storage values, prefix the parameter with a double underscore (__
).
- Each test should have a comment above the function name giving a high-level description of what the test is doing.
- Each test name that evaluates a failure case should contain "failure" in the function name.