Skip to content

Commit

Permalink
Merge pull request #1097 from cheng521521/main
Browse files Browse the repository at this point in the history
feat: upgrade etherjs v6
  • Loading branch information
yingjingyang authored Apr 25, 2024
2 parents 875593e + d98e3b2 commit 8de015f
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 117 deletions.
1 change: 1 addition & 0 deletions basic/13-decentralized-exchange/uniswap-v1-like/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ await exchange.getEthAmount(toWei(2000)); // 500
注意:我们最初基于汇率的定价函数没有错(恒定和公式的 AMM)。事实上,当我们交易的代币数量相对数量非常小时。但是要提供 AMM,我们需要更复杂的东西。

## Exchange 合约实现
![uniswap-exchange函数列表](./images/uniswap-exchange.png)

V1 的 Exchange 合约包含了定价、交易、添加/移除流动性、分发 LP token 代币功能。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ contract Exchange is ERC20 {
return getAmount(_tokenSold, tokenReserve, address(this).balance);
}



function ethToToken(uint256 _minTokens, address recipient) private {
uint256 tokenReserve = getReserve();
Expand Down Expand Up @@ -186,6 +186,7 @@ contract Exchange is ERC20 {
address(this).balance
);

//给 owner打钱
IERC20(tokenAddress).transferFrom(
msg.sender,
address(this),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require("@nomiclabs/hardhat-waffle");
const { utils } = require("ethers");
const { GAS_PRICE } = require("./utils")

require("@nomicfoundation/hardhat-toolbox");
const ethers = require('ethers');
// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async () => {
Expand All @@ -23,12 +21,12 @@ module.exports = {
hardhat: {
accounts: {
// 初始化账户给 1000000 eth 默认 100 不够用
accountsBalance: utils.parseEther("1000000").toString(),
accountsBalance: ethers.parseEther("1000000").toString(),
},
// gasPrice 1000000000 默认 8000000000
// 便于计算gas费用
gasPrice: GAS_PRICE.toNumber(),
gasPrice: 1000000000
},
},
solidity: "0.8.4",
solidity: "0.8.4"
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions basic/13-decentralized-exchange/uniswap-v1-like/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
},
"dependencies": {
"@openzeppelin/contracts": "^4.1.0",
"hardhat": "^2.3.0"
"hardhat": "^2.4.1"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-waffle": "^2.0.0",
"chai": "^4.2.0",
"ethereum-waffle": "^3.0.0",
"ethers": "^5.0.0"
"@nomicfoundation/edr-darwin-x64": "^0.3.3",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.6",
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"ethers": "^6.11.1"
}
}
Loading

0 comments on commit 8de015f

Please sign in to comment.