-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
blockmaxbu
committed
Feb 1, 2025
1 parent
e7747cd
commit ade7585
Showing
8 changed files
with
199 additions
and
123 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 |
---|---|---|
@@ -1,66 +1 @@ | ||
## Foundry | ||
|
||
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** | ||
|
||
Foundry consists of: | ||
|
||
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). | ||
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. | ||
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. | ||
- **Chisel**: Fast, utilitarian, and verbose solidity REPL. | ||
|
||
## Documentation | ||
|
||
https://book.getfoundry.sh/ | ||
|
||
## Usage | ||
|
||
### Build | ||
|
||
```shell | ||
$ forge build | ||
``` | ||
|
||
### Test | ||
|
||
```shell | ||
$ forge test | ||
``` | ||
|
||
### Format | ||
|
||
```shell | ||
$ forge fmt | ||
``` | ||
|
||
### Gas Snapshots | ||
|
||
```shell | ||
$ forge snapshot | ||
``` | ||
|
||
### Anvil | ||
|
||
```shell | ||
$ anvil | ||
``` | ||
|
||
### Deploy | ||
|
||
```shell | ||
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key> | ||
``` | ||
|
||
### Cast | ||
|
||
```shell | ||
$ cast <subcommand> | ||
``` | ||
|
||
### Help | ||
|
||
```shell | ||
$ forge --help | ||
$ anvil --help | ||
$ cast --help | ||
``` | ||
## ERC721 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,120 @@ | ||
//SPDX-License-Identifier: MIT | ||
// Layout of Contract: | ||
// version | ||
// imports | ||
// errors | ||
// interfaces, libraries, contracts | ||
// Type declarations | ||
// State variables | ||
// Events | ||
// Modifiers | ||
// Functions | ||
|
||
// Layout of Functions: | ||
// constructor | ||
// receive function (if exists) | ||
// fallback function (if exists) | ||
// external | ||
// public | ||
// internal | ||
// private | ||
// internal & private view & pure functions | ||
// external & public view & pure functionsP | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import {IERC721} from "./interfaces/IERC721.sol"; | ||
import {IERC721Receiver} from "./interfaces/IERC721Receiver.sol"; | ||
import {IERC165} from "./interfaces/IERC165.sol"; | ||
|
||
contract ERC721 is IERC721, IERC165 { | ||
|
||
//Constants | ||
bytes4 constant _ERC721_RECEIVED = bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")); | ||
|
||
// State variables | ||
mapping(uint256 => address) private _owners; | ||
mapping(address => uint256) private _balances; | ||
mapping(uint256 => address) private _tokenApprovals; | ||
mapping(address => mapping(address => bool)) private _operatorApprovals; | ||
|
||
// Events is defined in the interface | ||
|
||
// Modifiers | ||
modifier onlyOwner(uint256 tokenId) { | ||
require(_ownerOf(tokenId) == msg.sender, "ERC721: caller is not the owner"); | ||
_; | ||
} | ||
|
||
// Functions | ||
function supportsInterface(bytes4 interfaceId) external view override returns (bool) { | ||
return interfaceId == type(IERC721).interfaceId || interfaceId == type(IERC165).interfaceId; | ||
} | ||
|
||
function balanceOf(address owner) external view override returns (uint256) { | ||
require(owner != address(0), "ERC721: balance query for the zero address"); | ||
return _balances[owner]; | ||
} | ||
|
||
function ownerOf(uint256 tokenId) external view override returns (address) { | ||
address owner = _owners[tokenId]; | ||
require(owner != address(0), "ERC721: owner query for nonexistent token"); | ||
return owner; | ||
} | ||
|
||
function safeTransferFrom(address from, address to, uint256 tokenId) external override { | ||
|
||
} | ||
|
||
function transferFrom(address from, address to, uint256 tokenId) external override { | ||
address owner = _ownerOf(tokenId); | ||
require(owner == from, "ERC721: transfer of token that is not own"); | ||
require(to != address(0), "ERC721: transfer to the zero address"); | ||
_balances[from] -= 1; | ||
_balances[to] += 1; | ||
_owners[tokenId] = to; | ||
emit Transfer(from, to, tokenId); | ||
} | ||
|
||
|
||
function tokenURI(uint256 tokenId) external view override returns (string memory) { | ||
require(_owners[tokenId] != address(0), "ERC721: URI query for nonexistent token"); | ||
return ""; | ||
} | ||
|
||
function approve(address to, uint256 tokenId) external override { | ||
address owner = _ownerOf(tokenId); | ||
require(to != owner, "ERC721: approval to current owner"); | ||
require(msg.sender == owner, "ERC721: approve caller is not owner nor approved for all"); | ||
_tokenApprovals[tokenId] = to; | ||
emit Approval(owner, to, tokenId); | ||
} | ||
|
||
function getApproved(uint256 tokenId) external view returns (address) { | ||
require(_owners[tokenId] != address(0), "ERC721: approved query for nonexistent token"); | ||
return _tokenApprovals[tokenId]; | ||
} | ||
|
||
function isApprovedForAll(address owner, address operator) external view override returns (bool) { | ||
return _operatorApprovals[owner][operator]; | ||
} | ||
|
||
function setApprovalForAll(address operator, bool approved) external override { | ||
require(operator != msg.sender, "ERC721: approve to caller"); | ||
_operatorApprovals[msg.sender][operator] = approved; | ||
emit ApprovalForAll(msg.sender, operator, approved); | ||
} | ||
|
||
function _ownerOf(uint256 tokenId) internal view returns (address) { | ||
address owner = _owners[tokenId]; | ||
require(owner != address(0), "ERC721: owner query for nonexistent token"); | ||
return owner; | ||
} | ||
|
||
function _checkOnERC721Received(address from, address to, uint256 tokenId, bytes memory _data) internal returns (bool) { | ||
|
||
bytes4 retval = IERC721Receiver(to).onERC721Received(msg.sender, from, tokenId, _data); | ||
return (retval == _ERC721_RECEIVED); | ||
} | ||
|
||
} |
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 @@ | ||
//SPDX-Lisence-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
interface IERC165 { | ||
|
||
/** | ||
* @dev check if a contract implements an interface | ||
*/ | ||
function supportsInterface(bytes4 interfaceId) external view returns (bool); | ||
|
||
} |
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,61 @@ | ||
//SPDX-Lilicense-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
interface IERC721 { | ||
|
||
/** | ||
* @dev emitted when `tokenId` token is transferred from `from` to `to`. | ||
*/ | ||
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); | ||
|
||
/** | ||
* @dev emitted when `owner` enables `approved` to manage the `tokenId` token. | ||
*/ | ||
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); | ||
|
||
/** | ||
* @dev emitted when `owner` enables or disables `operator` to manage all of its assets. | ||
*/ | ||
event ApprovalForAll(address indexed owner, address indexed operator, bool approved); | ||
|
||
/** | ||
* @dev returns the number of tokens in `owner`'s account. | ||
*/ | ||
function balanceOf(address owner) external view returns (uint256); | ||
|
||
/** | ||
* @dev returns the owner of the `tokenId` token. | ||
*/ | ||
function ownerOf(uint256 tokenId) external view returns (address); | ||
|
||
/** | ||
* @dev transfers `tokenId` token from `from` to `to`. | ||
*/ | ||
function safeTransferFrom(address from, address to, uint256 tokenId) external; | ||
|
||
/** | ||
* @dev transfers `tokenId` token from `from` to `to`. | ||
*/ | ||
function transferFrom(address from, address to, uint256 tokenId) external; | ||
|
||
/** | ||
* @dev gives permission to `to` to transfer `tokenId` token. | ||
*/ | ||
function approve(address to, uint256 tokenId) external; | ||
|
||
/** | ||
* @dev gives permission to `to` to transfer all tokens of `owner`. | ||
*/ | ||
function setApprovalForAll(address to, bool approved) external; | ||
|
||
/** | ||
* @dev returns the `tokenId` token URI. | ||
*/ | ||
function tokenURI(uint256 tokenId) external view returns (string memory); | ||
|
||
/** | ||
* @dev checks if `tokenId` token is approved to be transferred by `to`. | ||
*/ | ||
function isApprovedForAll(address owner, address operator) external view returns (bool); | ||
|
||
} |
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,6 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
interface IERC721Receiver { | ||
function onERC721Received(address operator, address from, uint256 tokenId, bytes calldata data) external returns (bytes4); | ||
} |
This file was deleted.
Oops, something went wrong.