-
Notifications
You must be signed in to change notification settings - Fork 95
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
pool swap接口开发 #100
pool swap接口开发 #100
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
代码主要先往 https://github.com/WTFAcademy/WTF-Dapp/tree/main/demo-contract 这里提,保证工程可以跑起来 |
这个课程的代码不用单独放到课程的 |
function liquidity() external view returns (uint128); | ||
|
||
function positions( | ||
int8 positionType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gpteth 代码有些冲突了 |
P203_Connect/code/Pool.sol
Outdated
@@ -0,0 +1,2323 @@ | |||
// SPDX-License-Identifier: GPL-2.0-or-later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个文件是不是误提交了,合约代码应该都是在 demo-contract
里面吧?
) external; | ||
} | ||
|
||
interface IPool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里怎么重复定义了一个 IPool,而不是用 interfaces/IPool.sol
// 记录 token1 的每单位流动性所获取的手续费 | ||
uint256 public feeGrowthGlobal1X128; | ||
|
||
int24 public tickSpacing; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码格式有些问题,中间有多余空格。下面几行也有同样的问题。
int24 public tickSpacing; | ||
|
||
address public _factory; | ||
// address public factory; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// address public factory; |
int24 tickUpper_ | ||
) external override {} | ||
) external override { | ||
require(slot0.sqrtPriceX96 == 0, 'AI'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI
是什么的缩写?语义是不是可以更具体一点。不过我看 uni 的代码也是这么写的 https://github.com/Uniswap/v3-core/blob/main/contracts/UniswapV3Pool.sol#L272
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看了下,应该是 'AI' (Already Initialized)。的意思,感觉课程的话可以不用考虑节约 gas ,直接用 Already Initialized 这个语义更好,代码更容易懂。或者注释一下也行。
|
||
// emit Initialize(sqrtPriceX96, tick); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没用的代码就直接删掉吧
) external override { | ||
require(slot0.sqrtPriceX96 == 0, 'AI'); | ||
|
||
int24 tick = TickMath.getTickAtSqrtRatio(sqrtPriceX96); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
针对这些代码里面可以多一些注释,这样新手看代码学的时候会更好理解
|
||
function sqrtPriceX96() external view override returns (uint160) {} | ||
struct Slot0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有点好奇 uni 这个 struct 为什么要取一个 Slot0
的名字?为啥有一个 0
?
function mint( | ||
address recipient, | ||
int8 positionType, | ||
int24 tickLower, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在我们的设计里面,mint 方法应该没有 tickLower 和 tickUpper 了,这两个是在 Pool 上面的。
}); | ||
|
||
// 当剩余可交易金额为零,或交易后价格达到了限定的价格之后才退出循环 | ||
while (state.amountSpecifiedRemaining != 0 && state.sqrtPriceX96 != sqrtPriceLimitX96) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你这个应该还是整体参考了 Uniswap V3 的代码吧,V3 代码比较复杂。所以我们课程设计的时候做了调整。每个 Pool 都定义了价格上下限,不会出现一个 Pool 里面有不同价格区间的流动性。所以应该也不需要这样循环处理,你可以认为整个 Pool 里面的流动性都是在同一个价格区间内的,所以只要整个 Pool 没有超出价格就可以交易。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有空可以帮忙 review 下 #107 ,完善了设计上的一些细节
代码有冲突了 |
|
||
function token1() external view override returns (address) {} | ||
function transferETH(address _address, uint256 amount) public returns (bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们这个课程目前不需要实现原生代币的交易,只需要支持 ERC20 就行
pool swap接口开发