-
Notifications
You must be signed in to change notification settings - Fork 169
Feat/59 add natspec descriptions #549
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
38fe538
ff4dd4f
ad24f84
50636ed
688b242
9d40424
2a54021
eca0d50
ce61955
8e9e569
cc564f9
d0b743b
35212b8
8cf4a81
37dc690
946288b
5c44e50
23b1a74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
"@openzeppelin/contracts-wizard": patch | ||
--- | ||
|
||
Refine NatSpec documentation in generated contracts to improve developer experience: | ||
|
||
- Remove redundant parameter documentation where function signatures are self-explanatory | ||
- Add strategic documentation for non-obvious functions, focusing on implementation considerations | ||
- Preserve critical inheritance and function resolution comments in account contracts | ||
- Align documentation style with OpenZeppelin's contract library examples | ||
- Document override functions only when they add significant value | ||
|
||
This change follows the principle that documentation should provide insights beyond what's already visible in the code, while ensuring critical implementation details are preserved for developers. | ||
ericglau marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -400,16 +400,6 @@ function addSuperchainERC20(c: ContractBuilder) { | |
functions._checkTokenBridge, | ||
'pure', | ||
); | ||
c.setFunctionComments( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment text is still relevant for this scenario. It would be fine for it to overwrite the generic function comment for |
||
[ | ||
'/**', | ||
' * @dev Checks if the caller is the predeployed SuperchainTokenBridge. Reverts otherwise.', | ||
' *', | ||
' * IMPORTANT: The predeployed SuperchainTokenBridge is only available on chains in the Superchain.', | ||
' */', | ||
], | ||
functions._checkTokenBridge, | ||
); | ||
} | ||
|
||
export const functions = defineFunctions({ | ||
|
@@ -420,6 +410,9 @@ export const functions = defineFunctions({ | |
{ name: 'to', type: 'address' }, | ||
{ name: 'value', type: 'uint256' }, | ||
], | ||
comments: [ | ||
'/// @dev Hook that is called during any token transfer. This includes minting and burning. Override this function to add custom logic for token transfers.', | ||
], | ||
}, | ||
|
||
_approve: { | ||
|
@@ -428,42 +421,100 @@ export const functions = defineFunctions({ | |
{ name: 'owner', type: 'address' }, | ||
{ name: 'spender', type: 'address' }, | ||
{ name: 'value', type: 'uint256' }, | ||
{ name: 'emitEvent', type: 'bool' }, | ||
mrscottyrose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
], | ||
comments: [ | ||
'/// @dev Sets the allowance for a spender to spend tokens on behalf of an owner. This is an internal function that should be called from a public function with proper access control.', | ||
], | ||
}, | ||
|
||
mint: { | ||
kind: 'public' as const, | ||
_mint: { | ||
mrscottyrose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
kind: 'internal' as const, | ||
args: [ | ||
{ name: 'to', type: 'address' }, | ||
{ name: 'amount', type: 'uint256' }, | ||
{ name: 'account', type: 'address' }, | ||
{ name: 'value', type: 'uint256' }, | ||
], | ||
comments: [ | ||
'/// @dev Creates new tokens and assigns them to the specified account. This is an internal function that should be called from a public function with proper access control.', | ||
], | ||
}, | ||
|
||
_burn: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering why adding this function? |
||
kind: 'internal' as const, | ||
args: [ | ||
{ name: 'account', type: 'address' }, | ||
{ name: 'value', type: 'uint256' }, | ||
], | ||
comments: [ | ||
'/// @dev Destroys tokens from the specified account. This is an internal function that should be called from a public function with proper access control.', | ||
], | ||
}, | ||
|
||
_spendAllowance: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering why adding this function? |
||
kind: 'internal' as const, | ||
args: [ | ||
{ name: 'owner', type: 'address' }, | ||
{ name: 'spender', type: 'address' }, | ||
{ name: 'value', type: 'uint256' }, | ||
], | ||
comments: [ | ||
'/// @dev Decreases the allowance of a spender by the specified amount. This is called during token transfers to update allowances.', | ||
], | ||
}, | ||
|
||
pause: { | ||
kind: 'public' as const, | ||
args: [], | ||
comments: [ | ||
'/// @dev Pauses all token transfers.', | ||
'/// Consider implementing access control to restrict who can pause.', | ||
], | ||
}, | ||
|
||
unpause: { | ||
kind: 'public' as const, | ||
args: [], | ||
comments: [ | ||
'/// @dev Unpauses all token transfers.', | ||
'/// Consider implementing access control to restrict who can unpause.', | ||
], | ||
}, | ||
|
||
snapshot: { | ||
kind: 'public' as const, | ||
args: [], | ||
comments: [ | ||
'/// @dev Creates a new snapshot and returns its id.', | ||
'/// Consider implementing access control to restrict who can create snapshots.', | ||
], | ||
}, | ||
|
||
nonces: { | ||
kind: 'public' as const, | ||
args: [{ name: 'owner', type: 'address' }], | ||
returns: ['uint256'], | ||
mutability: 'view' as const, | ||
comments: [ | ||
'/// @dev Returns the current nonce for an owner.', | ||
'/// Used for permit signatures to prevent replay attacks.', | ||
], | ||
}, | ||
|
||
_checkTokenBridge: { | ||
kind: 'internal' as const, | ||
args: [{ name: 'caller', type: 'address' }], | ||
comments: [ | ||
'/// @dev Validates if the caller is an authorized token bridge. This is used for cross-chain token transfers to ensure only trusted bridges can move tokens.', | ||
], | ||
}, | ||
|
||
mint: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering why moving the functions orders here "mint" |
||
kind: 'public' as const, | ||
args: [ | ||
{ name: 'to', type: 'address' }, | ||
{ name: 'amount', type: 'uint256' }, | ||
], | ||
comments: [ | ||
'/// @dev Creates new tokens and assigns them to the specified account. This function should be called with proper access control to restrict who can mint tokens.', | ||
], | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,25 +216,34 @@ const functions = defineFunctions({ | |
_update: { | ||
kind: 'internal' as const, | ||
args: [ | ||
{ name: 'from', type: 'address' }, | ||
mrscottyrose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ name: 'to', type: 'address' }, | ||
{ name: 'tokenId', type: 'uint256' }, | ||
{ name: 'auth', type: 'address' }, | ||
], | ||
returns: ['address'], | ||
comments: [ | ||
'/// @dev Hook that is called during any token transfer. This includes minting and burning. Override this function to add custom logic for token transfers.', | ||
], | ||
}, | ||
|
||
tokenURI: { | ||
kind: 'public' as const, | ||
args: [{ name: 'tokenId', type: 'uint256' }], | ||
returns: ['string memory'], | ||
mutability: 'view' as const, | ||
comments: [ | ||
'/// @dev Returns the Uniform Resource Identifier (URI) for the specified token. This is used to store metadata for each token.', | ||
], | ||
}, | ||
|
||
_baseURI: { | ||
kind: 'internal' as const, | ||
args: [], | ||
returns: ['string memory'], | ||
mutability: 'pure' as const, | ||
mutability: 'view' as const, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this mutability be changed? Probably out of scope |
||
comments: [ | ||
'/// @dev Base URI for computing tokenURI. If set, the resulting URI for each token will be the concatenation of the baseURI and the tokenId.', | ||
], | ||
}, | ||
|
||
_increaseBalance: { | ||
|
@@ -243,10 +252,19 @@ const functions = defineFunctions({ | |
{ name: 'account', type: 'address' }, | ||
{ name: 'value', type: 'uint128' }, | ||
], | ||
comments: [ | ||
'/// @dev Increases the balance of an account. This is used internally to track token ownership and should not be called directly.', | ||
], | ||
}, | ||
}); | ||
|
||
function getMintFunction(incremental: boolean, uriStorage: boolean): BaseFunction { | ||
/** | ||
mrscottyrose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @dev Creates a mint function configuration based on the specified options | ||
* @param incremental Whether to use incremental token IDs | ||
* @param uriStorage Whether to include URI storage functionality | ||
* @return The configured mint function | ||
*/ | ||
const fn: BaseFunction = { | ||
name: 'safeMint', | ||
kind: 'public' as const, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing detailed change-set description