Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13-decentralized-exchange - upgrade etherjs v6 #1095

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
var ethers = require('ethers').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
Loading