-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Solidity files in docs (#4956)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
- Loading branch information
1 parent
6ae2c17
commit 0c18fac
Showing
16 changed files
with
152 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// contracts/MyNFT.sol | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {ERC721} from "../../token/ERC721/ERC721.sol"; | ||
|
||
contract MyNFT is ERC721 { | ||
constructor() ERC721("MyNFT", "MNFT") {} | ||
} |
14 changes: 14 additions & 0 deletions
14
contracts/mocks/docs/access-control/AccessControlModified.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// contracts/AccessControlModified.sol | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {AccessControl} from "../../../access/AccessControl.sol"; | ||
|
||
contract AccessControlModified is AccessControl { | ||
error AccessControlNonRevokable(); | ||
|
||
// Override the revokeRole function | ||
function revokeRole(bytes32, address) public pure override { | ||
revert AccessControlNonRevokable(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
contracts/mocks/docs/access-control/AccessControlUnrevokableAdmin.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// contracts/AccessControlNonRevokableAdmin.sol | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {AccessControl} from "../../../access/AccessControl.sol"; | ||
|
||
contract AccessControlNonRevokableAdmin is AccessControl { | ||
error AccessControlNonRevokable(); | ||
|
||
function revokeRole(bytes32 role, address account) public override { | ||
if (role == DEFAULT_ADMIN_ROLE) { | ||
revert AccessControlNonRevokable(); | ||
} | ||
|
||
super.revokeRole(role, account); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// contracts/GameItems.sol | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {ERC1155} from "../../../../token/ERC1155/ERC1155.sol"; | ||
|
||
contract GameItems is ERC1155 { | ||
uint256 public constant GOLD = 0; | ||
uint256 public constant SILVER = 1; | ||
uint256 public constant THORS_HAMMER = 2; | ||
uint256 public constant SWORD = 3; | ||
uint256 public constant SHIELD = 4; | ||
|
||
constructor() ERC1155("https://game.example/api/item/{id}.json") { | ||
_mint(msg.sender, GOLD, 10 ** 18, ""); | ||
_mint(msg.sender, SILVER, 10 ** 27, ""); | ||
_mint(msg.sender, THORS_HAMMER, 1, ""); | ||
_mint(msg.sender, SWORD, 10 ** 9, ""); | ||
_mint(msg.sender, SHIELD, 10 ** 9, ""); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
contracts/mocks/docs/token/ERC1155/MyERC115HolderContract.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// contracts/MyERC115HolderContract.sol | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {ERC1155Holder} from "../../../../token/ERC1155/utils/ERC1155Holder.sol"; | ||
|
||
contract MyERC115HolderContract is ERC1155Holder {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// contracts/GLDToken.sol | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {ERC20} from "../../../../token/ERC20/ERC20.sol"; | ||
|
||
contract GLDToken is ERC20 { | ||
constructor(uint256 initialSupply) ERC20("Gold", "GLD") { | ||
_mint(msg.sender, initialSupply); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// contracts/GameItem.sol | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {ERC721URIStorage, ERC721} from "../../../../token/ERC721/extensions/ERC721URIStorage.sol"; | ||
|
||
contract GameItem is ERC721URIStorage { | ||
uint256 private _nextTokenId; | ||
|
||
constructor() ERC721("GameItem", "ITM") {} | ||
|
||
function awardItem(address player, string memory tokenURI) public returns (uint256) { | ||
uint256 tokenId = _nextTokenId++; | ||
_mint(player, tokenId); | ||
_setTokenURI(tokenId, tokenURI); | ||
|
||
return tokenId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import {ERC721} from "../../../token/ERC721/ERC721.sol"; | ||
import {Strings} from "../../../utils/Strings.sol"; | ||
import {Base64} from "../../../utils/Base64.sol"; | ||
|
||
contract Base64NFT is ERC721 { | ||
using Strings for uint256; | ||
|
||
constructor() ERC721("Base64NFT", "MTK") {} | ||
|
||
// ... | ||
|
||
function tokenURI(uint256 tokenId) public pure override returns (string memory) { | ||
// Equivalent to: | ||
// { | ||
// "name": "Base64NFT #1", | ||
// // Replace with extra ERC-721 Metadata properties | ||
// } | ||
// prettier-ignore | ||
string memory dataURI = string.concat("{\"name\": \"Base64NFT #", tokenId.toString(), "\"}"); | ||
|
||
return string.concat("data:application/json;base64,", Base64.encode(bytes(dataURI))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// contracts/Box.sol | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {Multicall} from "../../../utils/Multicall.sol"; | ||
|
||
contract Box is Multicall { | ||
function foo() public { | ||
// ... | ||
} | ||
|
||
function bar() public { | ||
// ... | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters