Skip to content

Commit

Permalink
Merge pull request #757 from gitglorythegreat/main
Browse files Browse the repository at this point in the history
fix typos
  • Loading branch information
AmazingAng authored Oct 19, 2024
2 parents cc191ef + 1b1fe35 commit 88eb379
Show file tree
Hide file tree
Showing 29 changed files with 60 additions and 59 deletions.
4 changes: 2 additions & 2 deletions 24_Create/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ contract PairFactory{
}
```

工厂合约(`PairFactory`)有两个状态变量`getPair`是两个代币地址到币对地址的`map`,方便根据代币找到币对地址;`allPairs`是币对地址的数组,存储了所有代币地址
工厂合约(`PairFactory`)有两个状态变量`getPair`是两个代币地址到币对地址的`map`,方便根据代币找到币对地址;`allPairs`是币对地址的数组,存储了所有币对地址

`PairFactory`合约只有一个`createPair`函数,根据输入的两个代币地址`tokenA``tokenB`来创建新的`Pair`合约。其中

Expand Down Expand Up @@ -127,4 +127,4 @@ BSC链上的PEOPLE地址: 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c

## 总结

这一讲,我们用极简`Uniswap`的例子介绍了如何使用`create`方法再合约里创建合约,下一讲我们将介绍如何使用`create2`方法来实现极简`Uniswap`
这一讲,我们用极简`Uniswap`的例子介绍了如何使用`create`方法在合约里创建合约,下一讲我们将介绍如何使用`create2`方法来实现极简`Uniswap`
4 changes: 2 additions & 2 deletions 34_ERC721/ERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "./IERC721Metadata.sol";
import "./String.sol";

contract ERC721 is IERC721, IERC721Metadata{
using Strings for uint256; // 使用String库
using Strings for uint256; // 使用Strings库

// Token名称
string public override name;
Expand All @@ -21,7 +21,7 @@ contract ERC721 is IERC721, IERC721Metadata{
mapping(address => uint) private _balances;
// tokenID 到 授权地址 的授权映射
mapping(uint => address) private _tokenApprovals;
// owner地址。到operator地址 的批量授权映射
// owner地址 到 operator地址 的批量授权映射
mapping(address => mapping(address => bool)) private _operatorApprovals;

// 错误 无效的接收者
Expand Down
6 changes: 3 additions & 3 deletions 34_ERC721/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ import "./IERC721Metadata.sol";
import "./String.sol";
contract ERC721 is IERC721, IERC721Metadata{
using Strings for uint256; // 使用String库
using Strings for uint256; // 使用Strings库
// Token名称
string public override name;
Expand All @@ -222,7 +222,7 @@ contract ERC721 is IERC721, IERC721Metadata{
mapping(address => uint) private _balances;
// tokenID 到 授权地址 的授权映射
mapping(uint => address) private _tokenApprovals;
// owner地址。到operator地址 的批量授权映射
// owner地址 到 operator地址 的批量授权映射
mapping(address => mapping(address => bool)) private _operatorApprovals;
// 错误 无效的接收者
Expand Down Expand Up @@ -590,7 +590,7 @@ interface ERC721Metadata /* is ERC721 */ {
IERC721Metadata.name.selector ^ IERC721Metadata.symbol.selector ^ IERC721Metadata.tokenURI.selector
```

solamte实现的ERC721.sol是怎么完成这些ERC165要求的特性的呢?
solmate实现的ERC721.sol是怎么完成这些ERC165要求的特性的呢?

```solidity
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
Expand Down
8 changes: 4 additions & 4 deletions 35_DutchAuction/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ contract DutchAuction is Ownable, ERC721 {

合约中一共有`9`个状态变量,其中有`6`个和拍卖相关,他们是:

- `COLLECTOIN_SIZE`:NFT总量。
- `COLLECTION_SIZE`:NFT总量。
- `AUCTION_START_PRICE`:荷兰拍卖起拍价,也是最高价。
- `AUCTION_END_PRICE`:荷兰拍卖结束价,也是最低价/地板价。
- `AUCTION_TIME`:拍卖持续时长。
- `AUCTION_DROP_INTERVAL`:每过多久时间,价格衰减一次。
- `auctionStartTime`:拍卖起始时间(区块链时间戳,`block.timestamp`)。

```solidity
uint256 public constant COLLECTOIN_SIZE = 10000; // NFT总数
uint256 public constant COLLECTION_SIZE = 10000; // NFT总数
uint256 public constant AUCTION_START_PRICE = 1 ether; // 起拍价(最高价)
uint256 public constant AUCTION_END_PRICE = 0.1 ether; // 结束价(最低价/地板价)
uint256 public constant AUCTION_TIME = 10 minutes; // 拍卖时间,为了测试方便设为10分钟
Expand All @@ -82,7 +82,7 @@ contract DutchAuction is Ownable, ERC721 {
- 设定拍卖起始时间:我们在构造函数中会声明当前区块时间为起始时间,项目方也可以通过`setAuctionStartTime()`函数来调整:

```solidity
constructor() ERC721("WTF Dutch Auctoin", "WTF Dutch Auctoin") {
constructor() ERC721("WTF Dutch Auction", "WTF Dutch Auction") {
auctionStartTime = block.timestamp;
}
Expand Down Expand Up @@ -132,7 +132,7 @@ contract DutchAuction is Ownable, ERC721 {
"sale has not started yet"
); // 检查是否设置起拍时间,拍卖是否开始
require(
totalSupply() + quantity <= COLLECTOIN_SIZE,
totalSupply() + quantity <= COLLECTION_SIZE,
"not enough remaining reserved for auction to support desired mint amount"
); // 检查是否超过NFT上限
Expand Down
2 changes: 1 addition & 1 deletion 38_NFTSwap/NFTSwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ contract NFTSwap is IERC721Receiver {
require(_nft.getApproved(_tokenId) == address(this), "Need Approval"); // 合约得到授权
require(_price > 0); // 价格大于0

Order storage _order = nftList[_nftAddr][_tokenId]; //设置NF持有人和价格
Order storage _order = nftList[_nftAddr][_tokenId]; //设置NFT持有人和价格
_order.owner = msg.sender;
_order.price = _price;
// 将NFT转账到合约
Expand Down
35 changes: 18 additions & 17 deletions 38_NFTSwap/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,24 @@ contract NFTSwap is IERC721Receiver {

- 挂单`list()`:卖家创建`NFT`并创建订单,并释放`List`事件。参数为`NFT`合约地址`_nftAddr``NFT`对应的`_tokenId`,挂单价格`_price`**注意:单位是`wei`**)。成功后,`NFT`会从卖家转到`NFTSwap`合约中。

```solidity
// 挂单: 卖家上架NFT,合约地址为_nftAddr,tokenId为_tokenId,价格_price为以太坊(单位是wei)
function list(address _nftAddr, uint256 _tokenId, uint256 _price) public{
IERC721 _nft = IERC721(_nftAddr); // 声明IERC721接口合约变量
require(_nft.getApproved(_tokenId) == address(this), "Need Approval"); // 合约得到授权
require(_price > 0); // 价格大于0
Order storage _order = nftList[_nftAddr][_tokenId]; //设置NF持有人和价格
_order.owner = msg.sender;
_order.price = _price;
// 将NFT转账到合约
_nft.safeTransferFrom(msg.sender, address(this), _tokenId);
// 释放List事件
emit List(msg.sender, _nftAddr, _tokenId, _price);
}
```
```solidity
// 挂单: 卖家上架NFT,合约地址为_nftAddr,tokenId为_tokenId,价格_price为以太坊(单位是wei)
function list(address _nftAddr, uint256 _tokenId, uint256 _price) public{
IERC721 _nft = IERC721(_nftAddr); // 声明IERC721接口合约变量
require(_nft.getApproved(_tokenId) == address(this), "Need Approval"); // 合约得到授权
require(_price > 0); // 价格大于0
Order storage _order = nftList[_nftAddr][_tokenId]; //设置NFT持有人和价格
_order.owner = msg.sender;
_order.price = _price;
// 将NFT转账到合约
_nft.safeTransferFrom(msg.sender, address(this), _tokenId);
// 释放List事件
emit List(msg.sender, _nftAddr, _tokenId, _price);
}
```


- 撤单`revoke()`:卖家撤回挂单,并释放`Revoke`事件。参数为`NFT`合约地址`_nftAddr``NFT`对应的`_tokenId`。成功后,`NFT`会从`NFTSwap`合约转回卖家。

Expand Down
2 changes: 1 addition & 1 deletion 40_ERC1155/ERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import "../34_ERC721/IERC165.sol";
*/
contract ERC1155 is IERC165, IERC1155, IERC1155MetadataURI {
using Address for address; // 使用Address库,用isContract来判断地址是否为合约
using Strings for uint256; // 使用String库
using Strings for uint256; // 使用Strings库
// Token名称
string public name;
// Token代号
Expand Down
2 changes: 1 addition & 1 deletion 40_ERC1155/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ import "https://github.com/AmazingAng/WTF-Solidity/blob/main/34_ERC721/IERC165.s
*/
contract ERC1155 is IERC165, IERC1155, IERC1155MetadataURI {
using Address for address; // 使用Address库,用isContract来判断地址是否为合约
using Strings for uint256; // 使用String库
using Strings for uint256; // 使用Strings库
// Token名称
string public name;
// Token代号
Expand Down
2 changes: 1 addition & 1 deletion 46_ProxyContract/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fallback() external payable {
- `implementation`:占位变量,与`Proxy`合约保持一致,防止插槽冲突。
- `x``uint`变量,被设置为`99`
- `CallSuccess`事件:在调用成功时释放。
- `increment()`函数:会被`Proxy`合约调用,释放`CallSuccess`事件,并返回一个`uint`,它的`selector``0xd09de08a`。如果直接调用`increment()`回返回`100`,但是通过`Proxy`调用它会返回`1`,大家可以想想为什么?
- `increment()`函数:会被`Proxy`合约调用,释放`CallSuccess`事件,并返回一个`uint`,它的`selector``0xd09de08a`。如果直接调用`increment()`会返回`100`,但是通过`Proxy`调用它会返回`1`,大家可以想想为什么?

```solidity
/**
Expand Down
4 changes: 2 additions & 2 deletions 47_Upgrade/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ contract SimpleUpgrade {

### 旧逻辑合约

这个逻辑合约包含`3`个状态变量,与保持代理合约一致,防止插槽冲突。它只有一个函数`foo()`,将代理合约中的`words`的值改为`"old"`
这个逻辑合约包含`3`个状态变量,与代理合约保持一致,防止插槽冲突。它只有一个函数`foo()`,将代理合约中的`words`的值改为`"old"`

```solidity
// 逻辑合约1
Expand All @@ -98,7 +98,7 @@ contract Logic1 {

### 新逻辑合约

这个逻辑合约包含`3`个状态变量,与保持代理合约一致,防止插槽冲突。它只有一个函数`foo()`,将代理合约中的`words`的值改为`"new"`
这个逻辑合约包含`3`个状态变量,与代理合约保持一致,防止插槽冲突。它只有一个函数`foo()`,将代理合约中的`words`的值改为`"new"`

```solidity
// 逻辑合约2
Expand Down
2 changes: 1 addition & 1 deletion 48_TransparentProxy/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ contract TransparentProxy {

### 逻辑合约

这里的新、旧逻辑合约与[第47讲](https://github.com/AmazingAng/WTF-Solidity/blob/main/47_Upgrade/readme.md)一样。逻辑合约包含`3`个状态变量,与保持代理合约一致,防止插槽冲突;包含一个函数`foo()`,旧逻辑合约会将`words`的值改为`"old"`,新的会改为`"new"`
这里的新、旧逻辑合约与[第47讲](https://github.com/AmazingAng/WTF-Solidity/blob/main/47_Upgrade/readme.md)一样。逻辑合约包含`3`个状态变量,与代理合约保持一致,防止插槽冲突;包含一个函数`foo()`,旧逻辑合约会将`words`的值改为`"old"`,新的会改为`"new"`

```solidity
// 旧逻辑合约
Expand Down
2 changes: 1 addition & 1 deletion 49_UUPS/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ contract UUPSProxy {

### UUPS的逻辑合约

UUPS的逻辑合约与[第47讲](https://github.com/AmazingAng/WTF-Solidity/blob/main/47_Upgrade/readme.md)中的不同是多了个升级函数。UUPS逻辑合约包含`3`个状态变量,与保持代理合约一致,防止插槽冲突。它包含`2`
UUPS的逻辑合约与[第47讲](https://github.com/AmazingAng/WTF-Solidity/blob/main/47_Upgrade/readme.md)中的不同是多了个升级函数。UUPS逻辑合约包含`3`个状态变量,与代理合约保持一致,防止插槽冲突。它包含`2`
- `upgrade()`:升级函数,将改变逻辑合约地址`implementation`,只能由`admin`调用。
- `foo()`:旧UUPS逻辑合约会将`words`的值改为`"old"`,新的会改为`"new"`

Expand Down
2 changes: 1 addition & 1 deletion 50_MultisigWallet/MultisigWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract MultisigWallet {
function _setupOwners(address[] memory _owners, uint256 _threshold) internal {
// threshold没被初始化过
require(threshold == 0, "WTF5000");
// 多签执行门槛 小于 多签人数
// 多签执行门槛 小于或等于 多签人数
require(_threshold <= _owners.length, "WTF5001");
// 多签执行门槛至少为1
require(_threshold >= 1, "WTF5002");
Expand Down
6 changes: 3 additions & 3 deletions 50_MultisigWallet/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Gnosis Safe多签钱包是以太坊最流行的多签钱包,管理近400亿美
function _setupOwners(address[] memory _owners, uint256 _threshold) internal {
// threshold没被初始化过
require(threshold == 0, "WTF5000");
// 多签执行门槛 小于 多签人数
// 多签执行门槛 小于或等于 多签人数
require(_threshold <= _owners.length, "WTF5001");
// 多签执行门槛至少为1
require(_threshold >= 1, "WTF5002");
Expand Down Expand Up @@ -150,7 +150,7 @@ Gnosis Safe多签钱包是以太坊最流行的多签钱包,管理近400亿美
}
```

4. `checkSignatures()`:检查签名和交易数据的哈希是否对应,数量是否达到门槛,若否,交易会revert。单个签名长度为65字节,因此打包签名的长度要长于`threshold * 65`。调用了`signatureSplit()`分离出单个签名。这个函数的大致思路:
4. `checkSignatures()`:检查签名和交易数据的哈希是否对应,数量是否达到门槛,若否,交易会revert。单个签名长度为65字节,因此打包签名的长度要长于或等于`threshold * 65`。调用了`signatureSplit()`分离出单个签名。这个函数的大致思路:
- 用ecdsa获取签名地址.
- 利用 `currentOwner > lastOwner` 确定签名来自不同多签(多签地址递增)。
- 利用`isOwner[currentOwner]`确定签名者为多签持有人。
Expand Down Expand Up @@ -286,7 +286,7 @@ Gnosis Safe多签钱包是以太坊最流行的多签钱包,管理近400亿美
多签地址2的签名: 0x6b228b6033c097e220575f826560226a5855112af667e984aceca50b776f4c885e983f1f2155c294c86a905977853c6b1bb630c488502abcc838f9a225c813811c
讲两个签名拼接到一起,得到打包签名: 0xa3f3e4375f54ad0a8070f5abd64e974b9b84306ac0dd5f59834efc60aede7c84454813efd16923f1a8c320c05f185bd90145fd7a7b741a8d13d4e65a4722687e1b6b228b6033c097e220575f826560226a5855112af667e984aceca50b776f4c885e983f1f2155c294c86a905977853c6b1bb630c488502abcc838f9a225c813811c
将两个签名拼接到一起,得到打包签名: 0xa3f3e4375f54ad0a8070f5abd64e974b9b84306ac0dd5f59834efc60aede7c84454813efd16923f1a8c320c05f185bd90145fd7a7b741a8d13d4e65a4722687e1b6b228b6033c097e220575f826560226a5855112af667e984aceca50b776f4c885e983f1f2155c294c86a905977853c6b1bb630c488502abcc838f9a225c813811c
```

![签名](./img/50-5.png)
Expand Down
2 changes: 1 addition & 1 deletion Languages/en/34_ERC721_en/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ The calculation of **0x5b5e139f** is:
IERC721Metadata.name.selector ^ IERC721Metadata.symbol.selector ^ IERC721Metadata.tokenURI.selector
```

How does the ERC721.sol implemented by Solamte fulfil these features required by `ERC165`?
How does the ERC721.sol implemented by Solmate fulfil these features required by `ERC165`?

```solidity
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
Expand Down
4 changes: 2 additions & 2 deletions Languages/en/35_DutchAuction_en/DutchAuction.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "@openzeppelin/contracts/access/Ownable.sol";
import "../34_ERC721/ERC721.sol";

contract DutchAuction is Ownable, ERC721 {
uint256 public constant COLLECTOIN_SIZE = 10000; // Total number of NFTs
uint256 public constant COLLECTION_SIZE = 10000; // Total number of NFTs
uint256 public constant AUCTION_START_PRICE = 1 ether; // Starting price (highest price)
uint256 public constant AUCTION_END_PRICE = 0.1 ether; // End price (lowest price/floor price)
uint256 public constant AUCTION_TIME = 10 minutes; // Auction duration. Set to 10 minutes for testing convenience
Expand Down Expand Up @@ -46,7 +46,7 @@ contract DutchAuction is Ownable, ERC721 {
"sale has not started yet"
); // checks if the start time of auction has been set and auction has started
require(
totalSupply() + quantity <= COLLECTOIN_SIZE,
totalSupply() + quantity <= COLLECTION_SIZE,
"not enough remaining reserved for auction to support desired mint amount"
); // checks if the number of NFTs has exceeded the limit

Expand Down
4 changes: 2 additions & 2 deletions Languages/en/35_DutchAuction_en/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ There are a total of `9` state variables in the contract, of which `6` are relat
- `auctionStartTime`: Starting time of the auction (blockchain timestamp, `block.timestamp`).

```solidity
uint256 public constant COLLECTOIN_SIZE = 10000; // Total number of NFTs
uint256 public constant COLLECTION_SIZE = 10000; // Total number of NFTs
uint256 public constant AUCTION_START_PRICE = 1 ether; // Starting price (highest price)
uint256 public constant AUCTION_END_PRICE = 0.1 ether; // End price (lowest price/floor price)
uint256 public constant AUCTION_TIME = 10 minutes; // Auction duration. Set to 10 minutes for testing convenience
Expand Down Expand Up @@ -126,7 +126,7 @@ First, the function checks if the auction has started or if the number of `NFTs`
"sale has not started yet"
); // checks if the start time of auction has been set and auction has started
require(
totalSupply() + quantity <= COLLECTOIN_SIZE,
totalSupply() + quantity <= COLLECTION_SIZE,
"not enough remaining reserved for auction to support desired mint amount"
); // checks if the number of NFTs has exceeded the limit
Expand Down
2 changes: 1 addition & 1 deletion Languages/en/40_ERC1155_en/ERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import "../34_ERC721_en/IERC165.sol";
*/
contract ERC1155 is IERC165, IERC1155, IERC1155MetadataURI {
using Address for address; // use the Address library, isContract to determine whether the address is a contract
using Strings for uint256; // use the String library
using Strings for uint256; // use the Strings library
// Token name
string public name;
// Token code name
Expand Down
2 changes: 1 addition & 1 deletion Languages/en/40_ERC1155_en/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ import "../34_ERC721_en/IERC165.sol";
*/
contract ERC1155 is IERC165, IERC1155, IERC1155MetadataURI {
using Address for address; // use the Address library, isContract to determine whether the address is a contract
using Strings for uint256; // use the String library
using Strings for uint256; // use the Strings library
// Token name
string public name;
// Token code name
Expand Down
2 changes: 1 addition & 1 deletion Languages/en/50_MultisigWallet_en/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ Transaction hash: 0xb43ad6901230f2c59c3f7ef027c9a372f199661c61beeec49ef5a774231f
多签地址2的签名: 0xbe2e0e6de5574b7f65cad1b7062be95e7d73fe37dd8e888cef5eb12e964ddc597395fa48df1219e7f74f48d86957f545d0fbce4eee1adfbaff6c267046ade0d81c
讲两个签名拼接到一起,得到打包签名: 0x014db45aa753fefeca3f99c2cb38435977ebb954f779c2b6af6f6365ba4188df542031ace9bdc53c655ad2d4794667ec2495196da94204c56b1293d0fbfacbb11cbe2e0e6de5574b7f65cad1b7062be95e7d73fe37dd8e888cef5eb12e964ddc597395fa48df1219e7f74f48d86957f545d0fbce4eee1adfbaff6c267046ade0d81c
将两个签名拼接到一起,得到打包签名: 0x014db45aa753fefeca3f99c2cb38435977ebb954f779c2b6af6f6365ba4188df542031ace9bdc53c655ad2d4794667ec2495196da94204c56b1293d0fbfacbb11cbe2e0e6de5574b7f65cad1b7062be95e7d73fe37dd8e888cef5eb12e964ddc597395fa48df1219e7f74f48d86957f545d0fbce4eee1adfbaff6c267046ade0d81c
```

![Signature](./img/50-5-1.png)
Expand Down
4 changes: 2 additions & 2 deletions Languages/pt-br/35_DutchAuction/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ contract DutchAuction is Ownable, ERC721 {

Há um total de 9 variáveis de estado no contrato, sendo 6 relacionadas ao leilão. Elas são:

- `COLLECTOIN_SIZE`: total de NFTs.
- `COLLECTION_SIZE`: total de NFTs.
- `AUCTION_START_PRICE`: preço inicial e mais alto do leilão holandês.
- `AUCTION_END_PRICE`: preço final e mais baixo do leilão holandês.
- `AUCTION_TIME`: duração do leilão.
- `AUCTION_DROP_INTERVAL`: intervalo de tempo para a redução do preço.
- `auctionStartTime`: timestamp de início do leilão (utilizando `block.timestamp`).

```solidity
uint256 public constant COLLECTOIN_SIZE = 10000; // Total de NFTs
uint256 public constant COLLECTION_SIZE = 10000; // Total de NFTs
uint256 public constant AUCTION_START_PRICE = 1 ether; // Preço inicial (mais alto)
uint256 public constant AUCTION_END_PRICE = 0.1 ether; // Preço final (mais baixo)
uint256 public constant AUCTION_TIME = 10 minutes; // Duração do leilão, apenas para fins de teste
Expand Down
Loading

0 comments on commit 88eb379

Please sign in to comment.