Skip to content

Commit 602eba5

Browse files
committed
Updated documentation with comment style
1 parent 45dd2ae commit 602eba5

File tree

3 files changed

+133
-65
lines changed

3 files changed

+133
-65
lines changed

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
"solidity.compileUsingRemoteVersion": "v0.8.30",
88

99
// Enable GitHub Copilot
10-
"github.copilot.enable": true,
10+
"github.copilot.enable": {
11+
"*": true
12+
},
1113
"github.copilot.inlineSuggest.enable": true,
1214
"editor.inlineSuggest.enabled": true,
1315

website/docs/design/design-for-composition.mdx

Lines changed: 116 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ This requires reusing the `ERC20Storage` struct from `ERC20Facet` and defining a
7676
Here is the full `ERC20Storage` struct from `ERC20Facet`:
7777

7878
```solidity
79-
/// @notice Storage struct for ERC20.
80-
/// @custom:storage-location erc8042:compose.erc20
79+
/**
80+
* @notice Storage struct for ERC20.
81+
* @custom:storage-location erc8042:compose.erc20
82+
*/
8183
struct ERC20Storage {
8284
mapping(address owner => uint256 balance) balanceOf;
8385
uint256 totalSupply;
@@ -97,12 +99,16 @@ Only unused variables at the **end** of a struct may be safely removed. In this
9799
Here is the final struct storage code for `ERC20PermitFacet`:
98100

99101
```solidity
100-
/// @notice Storage slot identifier for ERC20 (reused to access token data).
102+
/**
103+
* @notice Storage slot identifier for ERC20 (reused to access token data).
104+
*/
101105
bytes32 constant ERC20_STORAGE_POSITION = keccak256("compose.erc20");
102106
103-
/// @notice Storage struct for ERC20 but with `symbol` removed.
104-
/// @dev Reused struct definition with unused variables at the end removed
105-
/// @custom:storage-location erc8042:compose.erc20
107+
/**
108+
* @notice Storage struct for ERC20 but with `symbol` removed.
109+
* @dev Reused struct definition with unused variables at the end removed
110+
* @custom:storage-location erc8042:compose.erc20
111+
*/
106112
struct ERC20Storage {
107113
mapping(address owner => uint256 balance) balanceOf;
108114
uint256 totalSupply;
@@ -111,26 +117,34 @@ struct ERC20Storage {
111117
string name;
112118
}
113119
114-
/// @notice Returns the storage for ERC20.
115-
/// @return s The ERC20 storage struct.
120+
/**
121+
* @notice Returns the storage for ERC20.
122+
* @return s The ERC20 storage struct.
123+
*/
116124
function getERC20Storage() internal pure returns (ERC20Storage storage s) {
117125
bytes32 position = ERC20_STORAGE_POSITION;
118126
assembly {
119127
s.slot := position
120128
}
121129
}
122130
123-
/// @notice Storage slot identifier for Permit functionality.
131+
/**
132+
* @notice Storage slot identifier for Permit functionality.
133+
*/
124134
bytes32 constant STORAGE_POSITION = keccak256("compose.erc20.permit");
125135
126-
/// @notice Storage struct for ERC20Permit.
127-
/// @custom:storage-location erc8042:compose.erc20.permit
136+
/**
137+
* @notice Storage struct for ERC20Permit.
138+
* @custom:storage-location erc8042:compose.erc20.permit
139+
*/
128140
struct ERC20PermitStorage {
129141
mapping(address owner => uint256) nonces;
130142
}
131143
132-
/// @notice Returns the storage for ERC20Permit.
133-
/// @return s The ERC20Permit storage struct.
144+
/**
145+
* @notice Returns the storage for ERC20Permit.
146+
* @return s The ERC20Permit storage struct.
147+
*/
134148
function getStorage() internal pure returns (ERC20PermitStorage storage s) {
135149
bytes32 position = STORAGE_POSITION;
136150
assembly {
@@ -155,137 +169,181 @@ function getStorage() internal pure returns (ERC20PermitStorage storage s) {
155169
Here's a complete example showing how to correctly extend `ERC20Facet` by creating a new `ERC20StakingFacet` that adds staking functionality:
156170

157171
```solidity
158-
// SPDX-License-Identifier: MIT
172+
/**
173+
* SPDX-License-Identifier: MIT
174+
*/
159175
pragma solidity >=0.8.30;
160176
161177
contract ERC20StakingFacet {
162-
/// @notice Standard ERC20 Transfer event.
178+
/**
179+
* @notice Standard ERC20 Transfer event.
180+
*/
163181
event Transfer(address indexed _from, address indexed _to, uint256 _value);
164182
165-
/// @notice Event emitted when tokens are staked.
166-
/// @param _account The account staking tokens.
167-
/// @param _amount The amount of tokens staked.
183+
/**
184+
* @notice Event emitted when tokens are staked.
185+
* @param _account The account staking tokens.
186+
* @param _amount The amount of tokens staked.
187+
*/
168188
event TokensStaked(address indexed _account, uint256 _amount);
169189
170-
/// @notice Event emitted when tokens are unstaked.
171-
/// @param _account The account unstaking tokens.
172-
/// @param _amount The amount of tokens unstaked.
190+
/**
191+
* @notice Event emitted when tokens are unstaked.
192+
* @param _account The account unstaking tokens.
193+
* @param _amount The amount of tokens unstaked.
194+
*/
173195
event TokensUnstaked(address indexed _account, uint256 _amount);
174196
175-
/// @notice Thrown when an account has insufficient balance for a stake operation.
176-
/// @param _sender Address attempting to stake.
177-
/// @param _balance Current balance of the sender.
178-
/// @param _needed Amount required to complete the operation.
197+
/**
198+
* @notice Thrown when an account has insufficient balance for a stake operation.
199+
* @param _sender Address attempting to stake.
200+
* @param _balance Current balance of the sender.
201+
* @param _needed Amount required to complete the operation.
202+
*/
179203
error ERC20InsufficientBalance(address _sender, uint256 _balance, uint256 _needed);
180204
181-
/// @notice Thrown when attempting to unstake more tokens than are staked.
182-
/// @param _account The account attempting to unstake.
183-
/// @param _requested The amount requested to unstake.
184-
/// @param _staked The amount currently staked.
205+
/**
206+
* @notice Thrown when attempting to unstake more tokens than are staked.
207+
* @param _account The account attempting to unstake.
208+
* @param _requested The amount requested to unstake.
209+
* @param _staked The amount currently staked.
210+
*/
185211
error InsufficientStakedBalance(address _account, uint256 _requested, uint256 _staked);
186212
187-
/// @notice Storage slot identifier for ERC20 (reused to access token data).
213+
/**
214+
* @notice Storage slot identifier for ERC20 (reused to access token data).
215+
*/
188216
bytes32 constant ERC20_STORAGE_POSITION = keccak256("compose.erc20");
189217
190-
/// @notice Storage struct for ERC20
191-
/// @dev This struct is from ERC20Facet.
192-
/// `balanceOf` is the only variable used in this struct.
193-
/// All variables after it are removed.
194-
/// @custom:storage-location erc8042:compose.erc20
218+
/**
219+
* @notice Storage struct for ERC20
220+
* @dev This struct is from ERC20Facet.
221+
* `balanceOf` is the only variable used in this struct.
222+
* All variables after it are removed.
223+
* @custom:storage-location erc8042:compose.erc20
224+
*/
195225
struct ERC20Storage {
196226
mapping(address owner => uint256 balance) balanceOf;
197227
}
198228
199-
/// @notice Returns the storage for ERC20.
200-
/// @return s The ERC20 storage struct.
229+
/**
230+
* @notice Returns the storage for ERC20.
231+
* @return s The ERC20 storage struct.
232+
*/
201233
function getERC20Storage() internal pure returns (ERC20Storage storage s) {
202234
bytes32 position = ERC20_STORAGE_POSITION;
203235
assembly {
204236
s.slot := position
205237
}
206238
}
207239
208-
/// @notice Storage slot identifier for Staking functionality.
240+
/**
241+
* @notice Storage slot identifier for Staking functionality.
242+
*/
209243
bytes32 constant STAKING_STORAGE_POSITION = keccak256("compose.erc20.staking");
210244
211-
/// @notice Storage struct for ERC20Staking.
212-
/// @custom:storage-location erc8042:compose.erc20.staking
245+
/**
246+
* @notice Storage struct for ERC20Staking.
247+
* @custom:storage-location erc8042:compose.erc20.staking
248+
*/
213249
struct ERC20StakingStorage {
214250
mapping(address account => uint256 stakedBalance) stakedBalances;
215251
mapping(address account => uint256 stakingStartTime) stakingStartTimes;
216252
}
217253
218-
/// @notice Returns the storage for ERC20Staking.
219-
/// @return s The ERC20Staking storage struct.
254+
/**
255+
* @notice Returns the storage for ERC20Staking.
256+
* @return s The ERC20Staking storage struct.
257+
*/
220258
function getStorage() internal pure returns (ERC20StakingStorage storage s) {
221259
bytes32 position = STAKING_STORAGE_POSITION;
222260
assembly {
223261
s.slot := position
224262
}
225263
}
226264
227-
/// @notice Stakes tokens from the caller's balance.
228-
/// @param _amount The amount of tokens to stake.
265+
/**
266+
* @notice Stakes tokens from the caller's balance.
267+
* @param _amount The amount of tokens to stake.
268+
*/
229269
function stake(uint256 _amount) external {
230270
ERC20Storage storage erc20s = getERC20Storage();
231271
ERC20StakingStorage storage s = getStorage();
232272
233-
// Check sufficient balance
273+
/**
274+
* Check sufficient balance
275+
*/
234276
if (erc20s.balanceOf[msg.sender] < _amount) {
235277
revert ERC20InsufficientBalance(msg.sender, erc20s.balanceOf[msg.sender], _amount);
236278
}
237279
238-
// Transfer tokens from user's balance to staked balance
280+
/**
281+
* Transfer tokens from user's balance to staked balance
282+
*/
239283
erc20s.balanceOf[msg.sender] -= _amount;
240284
erc20s.balanceOf[address(this)] += _amount;
241285
emit Transfer(msg.sender, address(this), _amount);
242286
243287
s.stakedBalances[msg.sender] += _amount;
244288
245-
// Record staking start time if this is the first stake
289+
/**
290+
* Record staking start time if this is the first stake
291+
*/
246292
if (s.stakingStartTimes[msg.sender] == 0) {
247293
s.stakingStartTimes[msg.sender] = block.timestamp;
248294
}
249295
250296
emit TokensStaked(msg.sender, _amount);
251297
}
252298
253-
/// @notice Unstakes tokens and returns them to the caller's balance.
254-
/// @param _amount The amount of tokens to unstake.
299+
/**
300+
* @notice Unstakes tokens and returns them to the caller's balance.
301+
* @param _amount The amount of tokens to unstake.
302+
*/
255303
function unstake(uint256 _amount) external {
256304
ERC20Storage storage erc20s = getERC20Storage();
257305
ERC20StakingStorage storage s = getStorage();
258306
259-
// Check sufficient staked balance
307+
/**
308+
* Check sufficient staked balance
309+
*/
260310
if (s.stakedBalances[msg.sender] < _amount) {
261311
revert InsufficientStakedBalance(msg.sender, _amount, s.stakedBalances[msg.sender]);
262312
}
263313
264-
// Transfer tokens from staked balance back to user's balance
314+
/**
315+
* Transfer tokens from staked balance back to user's balance
316+
*/
265317
s.stakedBalances[msg.sender] -= _amount;
266318
267319
erc20s.balanceOf[address(this)] -= _amount;
268320
erc20s.balanceOf[msg.sender] += _amount;
269321
emit Transfer(address(this), msg.sender, _amount);
270322
271-
// Clear staking start time if all tokens are unstaked
323+
/**
324+
* Clear staking start time if all tokens are unstaked
325+
*/
272326
if (s.stakedBalances[msg.sender] == 0) {
273327
s.stakingStartTimes[msg.sender] = 0;
274328
}
275329
276330
emit TokensUnstaked(msg.sender, _amount);
277331
}
278332
279-
/// @notice Returns the staked balance for an account.
280-
/// @param _account The account to check.
281-
/// @return The amount of tokens staked by the account.
333+
/**
334+
* @notice Returns the staked balance for an account.
335+
* @param _account The account to check.
336+
* @return The amount of tokens staked by the account.
337+
*/
282338
function getStakedBalance(address _account) external view returns (uint256) {
283339
return getStorage().stakedBalances[_account];
284340
}
285341
286-
/// @notice Returns the staking start time for an account.
287-
/// @param _account The account to check.
288-
/// @return The timestamp when the account first staked tokens.
342+
/**
343+
* @notice Returns the staking start time for an account.
344+
* @param _account The account to check.
345+
* @return The timestamp when the account first staked tokens.
346+
*/
289347
function getStakingStartTime(address _account) external view returns (uint256) {
290348
return getStorage().stakingStartTimes[_account];
291349
}

website/docs/foundations/custom-facets.mdx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,28 @@ Suppose you're building an on-chain game and want to include the `ERC721Facet` i
1515
You can add your own `GameNFTFacet` that extends functionality while still sharing the same ERC-721 storage through `LibERC721`:
1616

1717
```Solidity
18-
// Your custom facet integrates with Compose using libraries
18+
/**
19+
* Your custom facet integrates with Compose using libraries
20+
*/
1921
import {LibERC721} from "compose/LibERC721.sol";
2022
2123
contract GameNFTFacet {
2224
function mintWithGameLogic(address player, uint256 tokenId) external {
23-
// Your custom game logic
25+
/**
26+
* Your custom game logic
27+
*/
2428
require(playerHasEnoughPoints(player), "Not enough points");
2529
26-
// Use LibERC721 to mint - this modifies the SAME storage
27-
// that ERC721Facet uses for balanceOf(), ownerOf(), etc.
30+
/**
31+
* Use LibERC721 to mint - this modifies the SAME storage
32+
* that ERC721Facet uses for balanceOf(), ownerOf(), etc.
33+
*/
2834
LibERC721.mint(player, tokenId);
2935
30-
// Now the player owns this NFT and can use standard
31-
// ERC721Facet.transferFrom() to transfer it!
36+
/**
37+
* Now the player owns this NFT and can use standard
38+
* ERC721Facet.transferFrom() to transfer it!
39+
*/
3240
updatePlayerStats(player);
3341
}
3442
}

0 commit comments

Comments
 (0)