From 4c35c620fa5e21c37c25d60673c0d0bfd49418b6 Mon Sep 17 00:00:00 2001 From: xenoliss Date: Wed, 24 Apr 2024 19:54:36 +0200 Subject: [PATCH] Precise event naming convention (#14) * precise event naming convention * make event format clearer * split events section * fix syntax --- README.md | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cf99a5c..8b4893e 100644 --- a/README.md +++ b/README.md @@ -55,14 +55,40 @@ Custom errors are in some cases more gas efficient and allow passing useful info For example, `InsufficientBalance`. -#### 3. Event names should be past tense. +#### 3. Events -For example, `UpdatedOwner` not `UpdateOwner`. +##### A. Events names should be past tense. Events should track things that _happened_ and so should be past tense. Using past tense also helps avoid naming collisions with structs or functions. We are aware this does not follow precedent from early ERCs, like [ERC-20](https://eips.ethereum.org/EIPS/eip-20). However it does align with some more recent high profile Solidity, e.g. [1](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/976a3d53624849ecaef1231019d2052a16a39ce4/contracts/access/Ownable.sol#L33), [2](https://github.com/aave/aave-v3-core/blob/724a9ef43adf139437ba87dcbab63462394d4601/contracts/interfaces/IAaveOracle.sol#L25-L31), [3](https://github.com/ProjectOpenSea/seaport/blob/1d12e33b71b6988cbbe955373ddbc40a87bd5b16/contracts/zones/interfaces/PausableZoneEventsAndErrors.sol#L25-L41). +NO: + +```solidity +event OwnerUpdate(address newOwner); +``` + +YES: + +```solidity +event OwnerUpdated(address newOwner); +``` + +##### B. Prefer `SubjectVerb` naming format. + +NO: + +```solidity +event UpdatedOwner(address newOwner); +``` + +YES: + +```solidity +event OwnerUpdated(address newOwner); +``` + #### 4. Avoid using assembly. Assembly code is hard to read and audit. We should avoid it unless the gas savings are very consequential, e.g. > 25%.